Class: Connect::ValuesTable
- Inherits:
 - 
      Object
      
        
- Object
 - Connect::ValuesTable
 
 
- Defined in:
 - lib/connect/values_table.rb
 
Overview
A list of values that are indexed by a key name. The list can contain different kind of elements
Class Method Summary collapse
- 
  
    
      .object_reference_entry(name, object_type, object_name, selector = nil, xref = nil)  ⇒ Hash 
    
    
  
  
  
  
  
  
  
  
  
    
Create a object reference entry for the value table.
 - 
  
    
      .reference_entry(name, reference, selector = nil, xref = nil)  ⇒ Hash 
    
    
  
  
  
  
  
  
  
  
  
    
Create a reference entry for the value table.
 - 
  
    
      .value_entry(name, value, selector = nil, xref = nil)  ⇒ Hash 
    
    
  
  
  
  
  
  
  
  
  
    
Create a value entry for the value table.
 
Instance Method Summary collapse
- 
  
    
      #add(entry)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Add an entry to the values tables.
 - 
  
    
      #definitions(parameter)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
return the array of defintions for the specfied parameter.
 - 
  
    
      #dump  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
return the content of the values table in human readable format.
 - 
  
    
      #entries(name = /.*/)  ⇒ Array 
    
    
  
  
  
  
  
  
  
  
  
    
Give all entries in the values table based on the specfied name.
 - 
  
    
      #initialize  ⇒ ValuesTable 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of ValuesTable.
 - 
  
    
      #internal_lookup(name)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Lookup an entry in the values table.
 - 
  
    
      #lookup(name)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Finds an entry in the lookup table and translates it to the external representationof it.
 - 
  
    
      #references(parameter)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
return the array of references for the specfied parameter.
 - 
  
    
      #register_reference(parameter, xref)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Register a cross reference in the entry for the specfied parameter.
 
Constructor Details
#initialize ⇒ ValuesTable
Returns a new instance of ValuesTable.
      16 17 18  | 
    
      # File 'lib/connect/values_table.rb', line 16 def initialize @values_table = {} end  | 
  
Class Method Details
.object_reference_entry(name, object_type, object_name, selector = nil, xref = nil) ⇒ Hash
Create a object reference entry for the value table.
      163 164 165  | 
    
      # File 'lib/connect/values_table.rb', line 163 def self.object_reference_entry(name, object_type, object_name, selector = nil, xref = nil) { name => Entry::ObjectReference.new(object_type, object_name, selector, xref) } end  | 
  
.reference_entry(name, reference, selector = nil, xref = nil) ⇒ Hash
Create a reference entry for the value table.
      149 150 151  | 
    
      # File 'lib/connect/values_table.rb', line 149 def self.reference_entry(name, reference, selector = nil, xref = nil) { name => Entry::Reference.new(reference, selector, xref) } end  | 
  
Instance Method Details
#add(entry) ⇒ Object
Add an entry to the values tables
      72 73 74 75 76 77 78  | 
    
      # File 'lib/connect/values_table.rb', line 72 def add(entry) if exists?(entry) @values_table[entry.keys.first].merge!(entry.values.first) else @values_table.merge!(entry) end end  | 
  
#definitions(parameter) ⇒ Object
return the array of defintions for the specfied parameter
      37 38 39 40  | 
    
      # File 'lib/connect/values_table.rb', line 37 def definitions(parameter) entry = @values_table.fetch(parameter) { fail "internal error. Parameter entry #{parameter} not found" } entry.xref.collect {|e| e.class == Connect::Xdef ? [e.file_name, e.lineno] : nil}.compact end  | 
  
#dump ⇒ Object
return the content of the values table in human readable format
      86 87 88 89 90 91 92 93 94  | 
    
      # File 'lib/connect/values_table.rb', line 86 def dump output = '' @values_table.keys.sort.each do |key| # # Use inspect, to make ruby 1.8.7 and ruby 1.8 and higher compatible output << "#{key} = #{lookup(key).inspect}\n" end output end  | 
  
#entries(name = /.*/) ⇒ Array
Give all entries in the values table based on the specfied name. As name, you can specify a regular expression.
      27 28 29  | 
    
      # File 'lib/connect/values_table.rb', line 27 def entries( name = /.*/) @values_table.keys.select{| k| Regexp.new(name).match(k) }.sort end  | 
  
#internal_lookup(name) ⇒ Object
Lookup an entry in the values table
      114 115 116 117 118 119 120 121 122 123 124 125  | 
    
      # File 'lib/connect/values_table.rb', line 114 def internal_lookup(name) name = name.to_s # TODO: Check if name is a valid name if Gem::Version.new(::Hiera.version) > Gem::Version.new('2.0.0') @values_table.fetch(name) do Connect.debug("looked up '#{name}' but found nothing") throw :no_such_key end else @values_table.fetch(name) { Entry::Value.new(nil) } end end  | 
  
#lookup(name) ⇒ Object
Finds an entry in the lookup table and translates it to the external representationof it.
      103 104 105  | 
    
      # File 'lib/connect/values_table.rb', line 103 def lookup(name) internal_lookup(name).final end  | 
  
#references(parameter) ⇒ Object
return the array of references for the specfied parameter
      48 49 50 51  | 
    
      # File 'lib/connect/values_table.rb', line 48 def references(parameter) entry = @values_table.fetch(parameter) { fail "internal error. Parameter entry #{parameter} not found" } entry.xref.collect {|e| e.class == Connect::Xref ? [e.file_name, e.lineno] : nil}.compact end  | 
  
#register_reference(parameter, xref) ⇒ Object
Register a cross reference in the entry for the specfied parameter
      57 58 59 60 61 62 63 64  | 
    
      # File 'lib/connect/values_table.rb', line 57 def register_reference(parameter, xref) entry = @values_table.fetch(parameter) do value = Entry::Value.new(nil) add( parameter => value) value end entry.add_reference(xref) end  |