Class: Paquito::SerializedColumn
- Inherits:
-
Object
- Object
- Paquito::SerializedColumn
- Defined in:
- lib/paquito/serialized_column.rb
Instance Method Summary collapse
- #dump(object) ⇒ Object
-
#initialize(coder, type = nil, attribute_name: nil) ⇒ SerializedColumn
constructor
A new instance of SerializedColumn.
- #load(payload) ⇒ Object
- #object_class ⇒ Object
Constructor Details
#initialize(coder, type = nil, attribute_name: nil) ⇒ SerializedColumn
Returns a new instance of SerializedColumn.
5 6 7 8 9 10 11 |
# File 'lib/paquito/serialized_column.rb', line 5 def initialize(coder, type = nil, attribute_name: nil) @coder = coder @type = type @attribute_name = attribute_name || "Attribute" check_arity_of_constructor @default_value = type&.new end |
Instance Method Details
#dump(object) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/paquito/serialized_column.rb', line 25 def dump(object) return if object.nil? || object == @default_value check_type(object) @coder.dump(object) end |
#load(payload) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/paquito/serialized_column.rb', line 17 def load(payload) return @type&.new if payload.nil? object = @coder.load(payload) check_type(object) object || @type&.new end |
#object_class ⇒ Object
13 14 15 |
# File 'lib/paquito/serialized_column.rb', line 13 def object_class @type || Object end |