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

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

#as_json, #to_h

Instance Attribute Details

#coderObject

Returns the value of attribute coder

Returns:

  • (Object)

    the current value of coder



71
72
73
# File 'activerecord/lib/active_record/attribute_methods/serialization.rb', line 71

def coder
  @coder
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



71
72
73
# File 'activerecord/lib/active_record/attribute_methods/serialization.rb', line 71

def state
  @state
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



71
72
73
# File 'activerecord/lib/active_record/attribute_methods/serialization.rb', line 71

def value
  @value
end

Instance Method Details

#serializeObject



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

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

#serialized_valueObject



76
77
78
# File 'activerecord/lib/active_record/attribute_methods/serialization.rb', line 76

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

#unserialize(v) ⇒ Object



80
81
82
83
# File 'activerecord/lib/active_record/attribute_methods/serialization.rb', line 80

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

#unserialized_value(v = value) ⇒ Object



72
73
74
# File 'activerecord/lib/active_record/attribute_methods/serialization.rb', line 72

def unserialized_value(v = value)
  state == :serialized ? unserialize(v) : value
end