Class: ActiveRecord::AttributeMethods::Serialization::Attribute

Inherits:
Struct
  • Object
show all
Defined in:
activerecord/lib/active_record/attribute_methods/serialization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

#as_json

Instance Attribute Details

#coderObject

Returns the value of attribute coder

Returns:

  • (Object)

    the current value of coder



13
14
15
# File 'activerecord/lib/active_record/attribute_methods/serialization.rb', line 13

def coder
  @coder
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



13
14
15
# File 'activerecord/lib/active_record/attribute_methods/serialization.rb', line 13

def state
  @state
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



13
14
15
# File 'activerecord/lib/active_record/attribute_methods/serialization.rb', line 13

def value
  @value
end

Instance Method Details

#serializeObject



27
28
29
30
# File 'activerecord/lib/active_record/attribute_methods/serialization.rb', line 27

def serialize
  self.state = :serialized
  self.value = coder.dump(value)
end

#serialized_valueObject



18
19
20
# File 'activerecord/lib/active_record/attribute_methods/serialization.rb', line 18

def serialized_value
  state == :unserialized ? serialize : value
end

#unserializeObject



22
23
24
25
# File 'activerecord/lib/active_record/attribute_methods/serialization.rb', line 22

def unserialize
  self.state = :unserialized
  self.value = coder.load(value)
end

#unserialized_valueObject



14
15
16
# File 'activerecord/lib/active_record/attribute_methods/serialization.rb', line 14

def unserialized_value
  state == :serialized ? unserialize : value
end