Class: Conf

Inherits:
Object
  • Object
show all
Defined in:
lib/conf.rb

Defined Under Namespace

Modules: ConfigValue Classes: Configuration, InvalidKeyError, InvalidStateError

Class Method Summary collapse

Class Method Details

.configsObject

ConfigValue



64
65
66
# File 'lib/conf.rb', line 64

def self.configs
  @configs ||= {}
end

.define(name, parent = nil, &blk) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/conf.rb', line 68

def self.define(name, parent = nil, &blk)
  case parent
  when String, Symbol
    parent = get(parent)
  when Configuration, nil
    # ok
  else
    raise TypeError,
    "expected String, Symbol, Configuration or nil, got #{parent.inspect}:#{parent.class}"
  end

  conf = configs[name] ||= Configuration.new(parent)
  conf.instance_eval(&blk)

  conf.lock!
  conf
end

.get(name) ⇒ Object



86
87
88
# File 'lib/conf.rb', line 86

def self.get(name)
  configs[name] or raise ArgumentError, "no config named #{name.inspect}"
end