Module: Moon::DataModel::Fields::ModelCoercion

Included in:
ClassMethods
Defined in:
lib/data_model/fields/model_coercion.rb

Overview

Methods associated with converting objects to Models

Instance Method Summary collapse

Instance Method Details

#coerce(obj) ⇒ Object

Attempts to convert the provided object to the model


12
13
14
15
16
17
18
19
20
21
# File 'lib/data_model/fields/model_coercion.rb', line 12

def coerce(obj)
  if obj.is_a?(self)
    obj
  elsif obj.is_a?(Hash)
    new obj
  else
    # TODO, maybe fail here?
    obj
  end
end