Module: SerializedAttributes::InstanceMethods
- Defined in:
- lib/serialized_attributes.rb
Instance Method Summary collapse
- #create_or_update ⇒ Object
- #pack_serialized_attributes! ⇒ Object
- #unpack_serialized_attributes! ⇒ Object
Instance Method Details
#create_or_update ⇒ Object
47 48 49 50 |
# File 'lib/serialized_attributes.rb', line 47 def create_or_update pack_serialized_attributes! super end |
#pack_serialized_attributes! ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/serialized_attributes.rb', line 62 def pack_serialized_attributes! if @attributes.has_key?(serialized_attributes_column.to_s) attributes = self[serialized_attributes_column] ||= {} serialized_attributes_definition.each do |key, column| attributes[key] = self.send key end end attributes.slice!(*serialized_attributes_definition.keys) end |
#unpack_serialized_attributes! ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/serialized_attributes.rb', line 52 def unpack_serialized_attributes! if @attributes.has_key?(serialized_attributes_column.to_s) && attributes = (self[serialized_attributes_column] || {}) serialized_attributes_definition.each do |key, column| loaded_value = attributes.has_key?(key) ? attributes[key] : column.default @attributes[key] = attributes.has_key?(key) ? attributes[key] : column.default end attributes.slice!(*serialized_attributes_definition.keys) end end |