Class: Diva::Type::ModelType
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Attributes inherited from MetaType
Instance Method Summary collapse
- #cast(value) ⇒ Object
-
#initialize(model, *rest, &cast) ⇒ ModelType
constructor
A new instance of ModelType.
- #recommendation_point(value) ⇒ Object
- #schema ⇒ Object
- #to_s ⇒ Object
- #uri ⇒ Object
Methods inherited from MetaType
Constructor Details
#initialize(model, *rest, &cast) ⇒ ModelType
Returns a new instance of ModelType.
182 183 184 185 |
# File 'lib/diva/type.rb', line 182 def initialize(model, *rest, &cast) super(:model, *rest) @model = model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
180 181 182 |
# File 'lib/diva/type.rb', line 180 def model @model end |
Instance Method Details
#cast(value) ⇒ Object
191 192 193 194 195 196 197 198 199 200 |
# File 'lib/diva/type.rb', line 191 def cast(value) case value when model value when Hash model.new(value) else raise Diva::InvalidTypeError, "The value #{value.inspect} is not a `#{model}'." end end |
#recommendation_point(value) ⇒ Object
187 188 189 |
# File 'lib/diva/type.rb', line 187 def recommendation_point(value) value.is_a?(model) && 0 end |
#schema ⇒ Object
202 203 204 |
# File 'lib/diva/type.rb', line 202 def schema @schema ||= { type: uri }.freeze end |
#to_s ⇒ Object
206 207 208 |
# File 'lib/diva/type.rb', line 206 def to_s "#{model} #{name}" end |
#uri ⇒ Object
210 211 212 |
# File 'lib/diva/type.rb', line 210 def uri model.uri end |