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

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#coderObject

Returns the value of attribute coder

Returns:

  • (Object)

    the current value of coder



89
90
91
# File 'lib/active_record/attribute_methods/serialization.rb', line 89

def coder
  @coder
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



89
90
91
# File 'lib/active_record/attribute_methods/serialization.rb', line 89

def state
  @state
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



89
90
91
# File 'lib/active_record/attribute_methods/serialization.rb', line 89

def value
  @value
end

Instance Method Details

#serializeObject



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

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

#serialized_valueObject



94
95
96
# File 'lib/active_record/attribute_methods/serialization.rb', line 94

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

#unserialize(v) ⇒ Object



98
99
100
101
# File 'lib/active_record/attribute_methods/serialization.rb', line 98

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

#unserialized_value(v = value) ⇒ Object



90
91
92
# File 'lib/active_record/attribute_methods/serialization.rb', line 90

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