class Confuse::Definition
Public Class Methods
new(&block)
click to toggle source
# File lib/confuse/definition.rb, line 5 def initialize(&block) @default_namespace = :default block.call(self) end
Public Instance Methods
add_item(name, opts = {})
click to toggle source
# File lib/confuse/definition.rb, line 19 def add_item(name, opts = {}) namespaces[@default_namespace].add_item(name, opts) end
add_namespace(name, &block)
click to toggle source
# File lib/confuse/definition.rb, line 14 def add_namespace(name, &block) new_namespace = Namespace.new(name, &block) namespaces[name.to_sym] = new_namespace end
defines?(name)
click to toggle source
# File lib/confuse/definition.rb, line 10 def defines?(name) !!find_item_by_name(name) end
find_item(namespace, key)
click to toggle source
# File lib/confuse/definition.rb, line 34 def find_item(namespace, key) (ns = find_namespace(namespace)) && ns[key] end
namespace_and_key(name)
click to toggle source
# File lib/confuse/definition.rb, line 29 def namespace_and_key(name) KeySplitter.new(name).split.find { |(ns, _)| namespaces[ns] } || [nil, name] end
namespaces()
click to toggle source
# File lib/confuse/definition.rb, line 23 def namespaces @namespaces ||= { @default_namespace => Namespace.new(nil, &(Proc.new {})) } end
to_hash()
click to toggle source
# File lib/confuse/definition.rb, line 38 def to_hash @namespaces.reduce({}) { |a, (_k, v)| a.merge(v) } end
Private Instance Methods
find_item_by_name(name)
click to toggle source
# File lib/confuse/definition.rb, line 44 def find_item_by_name(name) namespace, key = namespace_and_key(name) end
find_namespace(name)
click to toggle source
# File lib/confuse/definition.rb, line 48 def find_namespace(name) namespaces[name || @default_namespace] end