lib/ultra_config/namespace.rb in ultra_config-0.9.0 vs lib/ultra_config/namespace.rb in ultra_config-0.9.1

- old
+ new

@@ -1,9 +1,11 @@ require_relative 'config' module UltraConfig class Namespace + class ObjectNotFoundError < StandardError; end + def initialize(&block) @configuration = [block] reset end @@ -16,28 +18,23 @@ Settings.set(name, value) end def namespace(name, &block) @objects[name] = Namespace.new(&block) + define_singleton_method(name) { @objects[name] } end def config(name, default = nil, options = {}, &block) @objects[name] = Config.new(default, options, &block) + define_singleton_method("#{name}=") { |value| @objects[name].value = value } + define_singleton_method(name) { @objects[name].value } end def helper(name, &block) define_singleton_method(name, &block) end - def method_missing(m, *args) - if m.to_s.end_with?('=') - @objects[m.to_s[0...-1].to_sym].value=(args[0]) - else - @objects[m].is_a?(Config) ? @objects[m].value : @objects[m] - end - end - def reset @objects = {} @configuration.each { |config| self.instance_eval(&config) } end @@ -59,8 +56,12 @@ hash[name] = object.to_h end end hash + end + + def method_missing(m) + raise ObjectNotFoundError end end end \ No newline at end of file