Module: Nilavu::MegamAttributes
- Included in:
- Megam::Mixins::Artifacts, Megam::Mixins::CommonDeployable, Megam::Mixins::InputGroupData, Megam::Mixins::Operations, Megam::Mixins::Repo, Megam::Outputs
- Defined in:
- lib/megam/mixins/megam_attributes.rb
Constant Summary collapse
- ATTRIBUTES =
[]
- KEY =
"key".freeze
- VALUE =
"value".freeze
Instance Method Summary collapse
- #attributes ⇒ Object
- #initialize(control_data = {}) ⇒ Object
- #set_attributes(control_data) ⇒ Object
- #to_hash ⇒ Object
Instance Method Details
#attributes ⇒ Object
8 9 10 |
# File 'lib/megam/mixins/megam_attributes.rb', line 8 def attributes NotImplementedError end |
#initialize(control_data = {}) ⇒ Object
11 12 13 |
# File 'lib/megam/mixins/megam_attributes.rb', line 11 def initialize(control_data={}) set_attributes(control_data) end |
#set_attributes(control_data) ⇒ Object
15 16 17 18 19 |
# File 'lib/megam/mixins/megam_attributes.rb', line 15 def set_attributes(control_data) #control_data.symbolize_keys! #control_data = Hash[control_data.map{ |k, v| [k.to_sym, v] }] attributes.each { |a| instance_variable_set("@#{a}", control_data[a]) unless control_data[a].nil? } end |
#to_hash ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/megam/mixins/megam_attributes.rb', line 21 def to_hash h = attributes.reduce([]) do |res, key| val = instance_variable_get("@#{key}".to_sym) res << { KEY => key.to_s, VALUE => val } unless val.nil? res end h end |