Module: ActiveRecord::AttributeMethods::Serialization

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_record/attribute_methods/serialization.rb

Defined Under Namespace

Modules: ClassMethods Classes: Attribute

Instance Method Summary collapse

Instance Method Details

#_field_changed?(attr, old, value) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
96
97
98
99
# File 'lib/active_record/attribute_methods/serialization.rb', line 93

def _field_changed?(attr, old, value)
  if self.class.serialized_attributes.include?(attr)
    old != value
  else
    super
  end
end

#attributes_before_type_castObject



109
110
111
112
113
114
115
116
117
# File 'lib/active_record/attribute_methods/serialization.rb', line 109

def attributes_before_type_cast
  super.dup.tap do |attributes|
    self.class.serialized_attributes.each_key do |key|
      if attributes.key?(key)
        attributes[key] = attributes[key].unserialized_value
      end
    end
  end
end

#read_attribute_before_type_cast(attr_name) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/active_record/attribute_methods/serialization.rb', line 101

def read_attribute_before_type_cast(attr_name)
  if serialized_attributes.include?(attr_name)
    super.unserialized_value
  else
    super
  end
end

#type_cast_attribute_for_write(column, value) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/active_record/attribute_methods/serialization.rb', line 85

def type_cast_attribute_for_write(column, value)
  if column && coder = self.class.serialized_attributes[column.name]
    Attribute.new(coder, value, :unserialized)
  else
    super
  end
end