Class: AppConfig::AccessorProxy
- Inherits:
-
HashWithIndifferentAccess
- Object
- HashWithIndifferentAccess
- AppConfig::AccessorProxy
- Defined in:
- lib/app_config/accessor_proxy.rb
Overview
Support nested hash accessors, so you could do AppConfig.stylesheet_expansions.standard
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/app_config/accessor_proxy.rb', line 7 def method_missing(method, *args, &block) if self[method] return AccessorProxy.new(self[method]) if self[method].is_a?(Hash) self[method] else begin super rescue NoMethodError => e # return default "value if nil" if one is provided if args.size == 1 args.first else raise e end end end end |
Instance Method Details
#convert_value(value) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/app_config/accessor_proxy.rb', line 25 def convert_value(value) case value when Hash AccessorProxy.new(value.with_indifferent_access) when Array value.collect { |e| e.is_a?(Hash) ? AccessorProxy.new(e.with_indifferent_access) : e } else value end end |