Module: Perpetuity::DataInjectable
- Included in:
- Mapper
- Defined in:
- lib/perpetuity/data_injectable.rb
Instance Method Summary collapse
- #give_id_to(object, *args) ⇒ Object
- #inject_attribute(object, attribute, value) ⇒ Object
- #inject_data(object, data) ⇒ Object
Instance Method Details
#give_id_to(object, *args) ⇒ Object
14 15 16 17 18 |
# File 'lib/perpetuity/data_injectable.rb', line 14 def give_id_to object, *args unless args.empty? inject_attribute object, :id, args.first end end |
#inject_attribute(object, attribute, value) ⇒ Object
3 4 5 |
# File 'lib/perpetuity/data_injectable.rb', line 3 def inject_attribute object, attribute, value object.instance_variable_set("@#{attribute}", value) end |
#inject_data(object, data) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/perpetuity/data_injectable.rb', line 7 def inject_data object, data data.each do |attribute,value| inject_attribute object, attribute, value end give_id_to object if object.instance_variables.include?(:@id) end |