Config

class
Superclass
Object
Included Modules
Enumerable
Extended With
Loggability

Constants

Item

Config item type

Attributes

items[R]

The Hash of Hglib::Config::Items from the config, keyed by name.

Public Class Methods

anchor
new( *config_items )

Create a new Config object from the given config_items.

# File lib/hglib/config.rb, line 21
def initialize( *config_items )
        @items = self.expand_config_items( config_items )
end

Public Instance Methods

anchor
[]( key )

Fetch the value of the config item key.

# File lib/hglib/config.rb, line 36
def []( key )
        return self.items[ key ]&.value
end
anchor
each( &block )

Call the block once for each config item, yielding the key and the Item.

# File lib/hglib/config.rb, line 42
def each( &block )
        return self.items.each( &block )
end
anchor
expand_config_items( items )

Expand the Array of configuration items such as that returned by the JSON template of `hg showconfig` and return a hierarchical Hash.

# File lib/hglib/config.rb, line 49
def expand_config_items( 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