Class: Confuse::Namespace
- Inherits:
-
Object
- Object
- Confuse::Namespace
- Defined in:
- lib/confuse/namespace.rb
Overview
A Namespace is a container to keep configuration data seperate from the rest of the config.
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add_item(name, opts = {}) ⇒ Object
-
#initialize(name, &block) ⇒ Namespace
constructor
A new instance of Namespace.
- #to_hash ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Namespace
Returns a new instance of Namespace.
9 10 11 12 13 |
# File 'lib/confuse/namespace.rb', line 9 def initialize(name, &block) @name = name @items = {} block.call(self) if block_given? end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
7 8 9 |
# File 'lib/confuse/namespace.rb', line 7 def items @items end |
Instance Method Details
#[](key) ⇒ Object
19 20 21 |
# File 'lib/confuse/namespace.rb', line 19 def [](key) @items[key] end |
#add_item(name, opts = {}) ⇒ Object
15 16 17 |
# File 'lib/confuse/namespace.rb', line 15 def add_item(name, opts = {}) @items[name] = Item.new(name, opts) end |
#to_hash ⇒ Object
23 24 25 26 27 28 |
# File 'lib/confuse/namespace.rb', line 23 def to_hash @items.reduce({}) do |a, (k,v)| key = @name ? :"#{@name}_#{k}" : k a.merge({ key => v.to_hash }) end end |