Module: SiteFuel::Processor::Configurable
- Included in:
- AbstractProcessor
- Defined in:
- lib/sitefuel/processors/Configurable.rb
Defined Under Namespace
Classes: UnknownConfigurationOption
Instance Method Summary collapse
-
#configuration_options ⇒ Object
gives a list of all configurable options for this class.
-
#configure(config = {}) ⇒ Object
configures a particular instance given a hash; runs #pre_configuration before running any particular config method and #post_configuration afterwards.
-
#ensure_configurable_option(name) ⇒ Object
ensures the given option name is configurable; otherwise raises a UnknownConfigurationOption exception.
- #post_configuration ⇒ Object
- #pre_configuration ⇒ Object
-
#set_configuration(key, value) ⇒ Object
sets the configuration for a single option.
Instance Method Details
#configuration_options ⇒ Object
gives a list of all configurable options for this class
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sitefuel/processors/Configurable.rb', line 29 def names = methods.map do |name| if name =~ /^configure_(.*)$/ $1.to_sym else nil end end names.compact end |
#configure(config = {}) ⇒ Object
configures a particular instance given a hash; runs #pre_configuration before running any particular config method and #post_configuration afterwards
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sitefuel/processors/Configurable.rb', line 55 def configure(config = {}) pre_configuration unless config == nil or config == {} config.each_pair do |k, v| set_configuration(k, v) end end post_configuration end |
#ensure_configurable_option(name) ⇒ Object
ensures the given option name is configurable; otherwise raises a UnknownConfigurationOption exception
70 71 72 73 74 75 76 |
# File 'lib/sitefuel/processors/Configurable.rb', line 70 def ensure_configurable_option (name) if .include?(name.to_sym) return true else raise UnknownConfigurationOption.new(self.class, name) end end |
#post_configuration ⇒ Object
47 48 49 |
# File 'lib/sitefuel/processors/Configurable.rb', line 47 def post_configuration # stub to be overriden by child classes end |
#pre_configuration ⇒ Object
42 43 44 |
# File 'lib/sitefuel/processors/Configurable.rb', line 42 def pre_configuration # stub to be overriden by child classes end |
#set_configuration(key, value) ⇒ Object
sets the configuration for a single option
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sitefuel/processors/Configurable.rb', line 80 def set_configuration(key, value) ensure_configurable_option(key) method = "configure_" + key.to_s case value when Array send(method.to_sym, *value) else send(method.to_sym, value) end end |