Class: EmbeddedModel::Type

Inherits:
ActiveRecord::Type::Internal::AbstractJson
  • Object
show all
Defined in:
lib/embedded_model/type.rb

Instance Method Summary collapse

Constructor Details

#initialize(&builder) ⇒ Type

Returns a new instance of Type.



3
4
5
# File 'lib/embedded_model/type.rb', line 3

def initialize(&builder)
  @builder = builder
end

Instance Method Details

#cast(attrs) ⇒ Object



7
8
9
# File 'lib/embedded_model/type.rb', line 7

def cast(attrs)
  @builder.call(attrs)
end

#deserialize(json) ⇒ Object



15
16
17
# File 'lib/embedded_model/type.rb', line 15

def deserialize(json)
  cast(super)
end

#serialize(obj) ⇒ Object



11
12
13
# File 'lib/embedded_model/type.rb', line 11

def serialize(obj)
  super(obj.as_json)
end