Class: NestedRecord::Type
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- NestedRecord::Type
- Defined in:
- lib/nested_record/type.rb,
lib/nested_record/type/one.rb,
lib/nested_record/type/many.rb
Defined Under Namespace
Instance Method Summary collapse
- #cast(data) ⇒ Object
- #deserialize(value) ⇒ Object
-
#initialize(setup) ⇒ Type
constructor
A new instance of Type.
- #serialize(obj) ⇒ Object
Constructor Details
#initialize(setup) ⇒ Type
Returns a new instance of Type.
7 8 9 |
# File 'lib/nested_record/type.rb', line 7 def initialize(setup) @setup = setup end |
Instance Method Details
#cast(data) ⇒ Object
11 12 13 |
# File 'lib/nested_record/type.rb', line 11 def cast(data) cast_value(data) end |
#deserialize(value) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/nested_record/type.rb', line 15 def deserialize(value) value = if value.is_a?(::String) ActiveSupport::JSON.decode(value) rescue nil else value end cast_value(value) end |
#serialize(obj) ⇒ Object
24 25 26 |
# File 'lib/nested_record/type.rb', line 24 def serialize(obj) ActiveSupport::JSON.encode(obj.as_json) unless obj.nil? end |