Module: SerializedAttributes::InstanceMethods
- Defined in:
- lib/serialized_attributes/serialized_attributes.rb
Instance Method Summary collapse
- #create_or_update ⇒ Object
- #pack_serialized_attributes! ⇒ Object
- #serialized_attribute_names ⇒ Object
- #unpack_serialized_attributes! ⇒ Object
Instance Method Details
#create_or_update ⇒ Object
51 52 53 54 |
# File 'lib/serialized_attributes/serialized_attributes.rb', line 51 def create_or_update pack_serialized_attributes! super end |
#pack_serialized_attributes! ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/serialized_attributes/serialized_attributes.rb', line 70 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 |
#serialized_attribute_names ⇒ Object
56 57 58 |
# File 'lib/serialized_attributes/serialized_attributes.rb', line 56 def serialized_attribute_names self.class.serialized_attribute_names end |
#unpack_serialized_attributes! ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/serialized_attributes/serialized_attributes.rb', line 60 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 |