Class: Acta::ModelType
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- Acta::ModelType
- Defined in:
- lib/acta/model_type.rb
Instance Method Summary collapse
- #cast(value) ⇒ Object
- #deserialize(value) ⇒ Object
-
#initialize(wrapped_class) ⇒ ModelType
constructor
A new instance of ModelType.
- #serialize(value) ⇒ Object
Constructor Details
#initialize(wrapped_class) ⇒ ModelType
Returns a new instance of ModelType.
7 8 9 10 |
# File 'lib/acta/model_type.rb', line 7 def initialize(wrapped_class) super() @wrapped_class = wrapped_class end |
Instance Method Details
#cast(value) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/acta/model_type.rb', line 12 def cast(value) case value when nil then nil when @wrapped_class then value when Hash then @wrapped_class.from_acta_hash(value) else raise ArgumentError, "Cannot cast #{value.class} (#{value.inspect}) to #{@wrapped_class}" end end |
#deserialize(value) ⇒ Object
28 29 30 |
# File 'lib/acta/model_type.rb', line 28 def deserialize(value) cast(value) end |
#serialize(value) ⇒ Object
22 23 24 25 26 |
# File 'lib/acta/model_type.rb', line 22 def serialize(value) return nil if value.nil? value.to_acta_hash end |