Class: Cumulus::Utils::ParametersHandler
- Inherits:
-
Object
- Object
- Cumulus::Utils::ParametersHandler
- Defined in:
- lib/cumulus/utils/parameters_handler.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Instance Method Summary collapse
- #cleanup(attributes) ⇒ Object
- #for_request ⇒ Object
-
#initialize(parameters, object) ⇒ ParametersHandler
constructor
A new instance of ParametersHandler.
- #set(attributes) ⇒ Object
Constructor Details
#initialize(parameters, object) ⇒ ParametersHandler
Returns a new instance of ParametersHandler.
6 7 8 9 |
# File 'lib/cumulus/utils/parameters_handler.rb', line 6 def initialize(parameters, object) @parameters = parameters @object = object end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
4 5 6 |
# File 'lib/cumulus/utils/parameters_handler.rb', line 4 def object @object end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
4 5 6 |
# File 'lib/cumulus/utils/parameters_handler.rb', line 4 def parameters @parameters end |
Instance Method Details
#cleanup(attributes) ⇒ Object
20 21 22 23 |
# File 'lib/cumulus/utils/parameters_handler.rb', line 20 def cleanup(attributes) Hash[attributes.map { |k, v| [k.to_s, v] }] .select { |k, v| parameters.key?(k) } end |
#for_request ⇒ Object
11 12 13 14 |
# File 'lib/cumulus/utils/parameters_handler.rb', line 11 def for_request parameters.each_with_object({}) { |j, k| k[j[1]] = object.send(j[0]) } .reject { |k, v| v.nil? } end |
#set(attributes) ⇒ Object
16 17 18 |
# File 'lib/cumulus/utils/parameters_handler.rb', line 16 def set(attributes) cleanup(attributes).each { |k, v| object.send("#{k}=", v) } end |