lib/complex_config/proxy.rb in complex_config-0.9.2 vs lib/complex_config/proxy.rb in complex_config-0.10.0

- old
+ new

@@ -16,21 +16,36 @@ ::ComplexConfig::Provider.flush_cache self end def method_missing(name, *args) - config = ::ComplexConfig::Provider[name] - (class << self; self; end).class_eval do - define_method(name) do |env = nil| - if env - config[env] - elsif @env - config[@env] - else - config + if name =~ /\?\z/ + method_name, name = name, $` + exist = ::ComplexConfig::Provider.exist?(name) + (class << self; self; end).class_eval do + define_method(method_name) do |env = nil| + if exist + __send__(name, *args) + else + nil + end end end + __send__(method_name, *args) + else + config = ::ComplexConfig::Provider[name] + (class << self; self; end).class_eval do + define_method(name) do |env = nil| + if env + config[env] + elsif @env + config[@env] + else + config + end + end + end + __send__(name, *args) end - __send__(name, *args) end end end