Class: Hglib::Config

Inherits:
Object
  • Object
show all
Extended by:
Loggability
Includes:
Enumerable
Defined in:
lib/hglib/config.rb

Defined Under Namespace

Classes: Item

Instance Attribute Summary collapse

Instance Method Summary collapse

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.expand_config_items( config_items )
end

Instance Attribute Details

#itemsObject (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 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