Module: Dragonfly::Configurable::InstanceMethods
- Defined in:
- lib/dragonfly/configurable.rb
Instance Method Summary collapse
- #config_methods ⇒ Object
- #configuration ⇒ Object
- #configure {|ConfigurationProxy.new(self)| ... } ⇒ Object
- #configure_with(config, *args, &block) ⇒ Object
- #default_configuration ⇒ Object
- #has_config_method?(method_name) ⇒ Boolean
- #set_config_value(key, value) ⇒ Object
- #use_as_fallback_config(other_configurable) ⇒ Object
Instance Method Details
#config_methods ⇒ Object
50 51 52 |
# File 'lib/dragonfly/configurable.rb', line 50 def config_methods @config_methods ||= configured_class.config_methods.dup end |
#configuration ⇒ Object
54 55 56 |
# File 'lib/dragonfly/configurable.rb', line 54 def configuration @configuration ||= {} end |
#configure {|ConfigurationProxy.new(self)| ... } ⇒ Object
34 35 36 37 |
# File 'lib/dragonfly/configurable.rb', line 34 def configure(&block) yield ConfigurationProxy.new(self) self end |
#configure_with(config, *args, &block) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/dragonfly/configurable.rb', line 39 def configure_with(config, *args, &block) config = saved_config_for(config) if config.is_a?(Symbol) config.apply_configuration(self, *args) configure(&block) if block self end |
#default_configuration ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/dragonfly/configurable.rb', line 58 def default_configuration # Merge the default configuration of all ancestor classes/modules which are configurable @default_configuration ||= [self.class, configured_class, *configured_class.ancestors].reverse.inject({}) do |default_config, klass| default_config.merge!(klass.default_configuration) if klass.respond_to? :default_configuration default_config end end |
#has_config_method?(method_name) ⇒ Boolean
46 47 48 |
# File 'lib/dragonfly/configurable.rb', line 46 def has_config_method?(method_name) config_methods.include?(method_name.to_sym) end |
#set_config_value(key, value) ⇒ Object
66 67 68 69 70 |
# File 'lib/dragonfly/configurable.rb', line 66 def set_config_value(key, value) configuration[key] = value child_configurables.each{|c| c.set_if_unset(key, value) } value end |
#use_as_fallback_config(other_configurable) ⇒ Object
72 73 74 75 |
# File 'lib/dragonfly/configurable.rb', line 72 def use_as_fallback_config(other_configurable) other_configurable.add_child_configurable(self) self.fallback_configurable = other_configurable end |