Class: Confuse::Namespace

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

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



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