Class: Hglib::Config
- Inherits:
-
Object
- Object
- Hglib::Config
- Extended by:
- Loggability
- Includes:
- Enumerable
- Defined in:
- lib/hglib/config.rb
Defined Under Namespace
Classes: Item
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
The Hash of Hglib::Config::Items from the config, keyed by name.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Fetch the value of the config item
key. -
#each(&block) ⇒ Object
Call the block once for each config item, yielding the key and the Item.
-
#expand_config_items(items) ⇒ Object
Expand the Array of configuration
itemssuch as that returned by the JSON template of ‘hg showconfig` and return a hierarchical Hash. -
#initialize(*config_items) ⇒ Config
constructor
Create a new Config object from the given
config_items.
Constructor Details
#initialize(*config_items) ⇒ Config
Create a new Config object from the given config_items.
22 23 24 |
# File 'lib/hglib/config.rb', line 22 def initialize( *config_items ) @items = self.( config_items ) end |
Instance Attribute Details
#items ⇒ Object (readonly)
The Hash of Hglib::Config::Items from the config, keyed by name.
33 34 35 |
# File 'lib/hglib/config.rb', line 33 def items @items end |
Instance Method Details
#[](key) ⇒ Object
Fetch the value of the config item key.
37 38 39 |
# File 'lib/hglib/config.rb', line 37 def []( key ) return self.items[ key ]&.value end |
#each(&block) ⇒ Object
Call the block once for each config item, yielding the key and the Item.
43 44 45 |
# File 'lib/hglib/config.rb', line 43 def each( &block ) return self.items.each( &block ) end |
#expand_config_items(items) ⇒ Object
Expand the Array of configuration items such as that returned by the JSON template of ‘hg showconfig` and return a hierarchical Hash.
50 51 52 53 54 55 |
# File 'lib/hglib/config.rb', line 50 def ( items ) return items.flatten.each_with_object( {} ) do |item, hash| self.log.debug "Expanding %p" % [ item ] hash[ item[:name] ] = Item.new( item[:value], item[:source] ) end end |