Class: Dragonfly::Configurable::ConfigurationProxy
- Defined in:
- lib/dragonfly/configurable.rb
Instance Method Summary collapse
-
#initialize(owner) ⇒ ConfigurationProxy
constructor
A new instance of ConfigurationProxy.
- #method_missing(method_name, *args, &block) ⇒ Object
Constructor Details
#initialize(owner) ⇒ ConfigurationProxy
Returns a new instance of ConfigurationProxy.
177 178 179 |
# File 'lib/dragonfly/configurable.rb', line 177 def initialize(owner) @owner = owner end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/dragonfly/configurable.rb', line 181 def method_missing(method_name, *args, &block) if owner.has_config_method?(method_name) attribute = method_name.to_s.tr('=','').to_sym if method_name.to_s =~ /=$/ && owner.has_config_method?(attribute) # a bit hacky - if it has both getter and setter, assume it's a configurable_attr owner.set_config_value(attribute, args.first) else owner.send(method_name, *args, &block) end elsif nested_configurable?(method_name) owner.send(method_name) else raise BadConfigAttribute, "You tried to configure using '#{method_name.inspect}', but the valid config attributes are #{owner.config_methods.map{|a| %('#{a.inspect}') }.sort.join(', ')}" end end |