Module: Stale::Parameters
- Included in:
- Configuration
- Defined in:
- lib/stale/parameters.rb
Instance Method Summary collapse
- #define_named_parameter(method, &block) ⇒ Object (also: #parameter)
- #key_for_parameter(parameter, controller = nil) ⇒ Object
- #key_for_parameters(parameters, controller = nil) ⇒ Object
- #named_parameters ⇒ Object
Instance Method Details
#define_named_parameter(method, &block) ⇒ Object Also known as: parameter
21 22 23 24 |
# File 'lib/stale/parameters.rb', line 21 def define_named_parameter(method, &block) block = method.to_proc unless block_given? self.named_parameters[method] = block end |
#key_for_parameter(parameter, controller = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/stale/parameters.rb', line 7 def key_for_parameter(parameter, controller = nil) if parameter.is_a?(Symbol) self.named_parameters[parameter].call(controller) elsif parameter.respond_to?(Model::IDENTIFIER) parameter.send(Model::IDENTIFIER) elsif parameter.is_a?(Class) Stale.interface.key_for_model(parameter) elsif parameter.is_a?(Array) Stale.interface.key_for_model(*parameter) else parameter.to_param end end |
#key_for_parameters(parameters, controller = nil) ⇒ Object
3 4 5 |
# File 'lib/stale/parameters.rb', line 3 def key_for_parameters(parameters, controller = nil) parameters.map { |parameter| key_for_parameter(parameter, controller) } end |
#named_parameters ⇒ Object
27 28 29 |
# File 'lib/stale/parameters.rb', line 27 def named_parameters @named_parameters ||= {} end |