Module: Refinery::Flare::HashInitializer::ClassMethods
- Defined in:
- app/models/refinery/flare/hash_initializer.rb
Instance Method Summary collapse
Instance Method Details
#attr_hashable_model(attribute, model) ⇒ Object
12 13 14 15 16 17 |
# File 'app/models/refinery/flare/hash_initializer.rb', line 12 def attr_hashable_model(attribute, model) attr_accessor attribute define_method "#{attribute}=" do |props| instance_variable_set("@#{attribute}", model.new(props)) end end |
#attr_hashable_models(attribute, model) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/refinery/flare/hash_initializer.rb', line 19 def attr_hashable_models(attribute, model) attr_accessor attribute define_method "#{attribute}=" do |props| # Initialize attribute if instance_variable_get("@#{attribute}").nil? instance_variable_set("@#{attribute}", []) end props.each do |part| instance_variable_get("@#{attribute}") << model.new(part) end end end |