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(v) ⇒ 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.
181 182 183 184 |
# File 'lib/diva/type.rb', line 181 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
190 191 192 193 194 195 196 197 198 199 |
# File 'lib/diva/type.rb', line 190 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(v) ⇒ Object
186 187 188 |
# File 'lib/diva/type.rb', line 186 def recommendation_point(v) v.is_a?(model) && 0 end |
#schema ⇒ Object
201 202 203 |
# File 'lib/diva/type.rb', line 201 def schema @schema ||= {type: uri}.freeze end |
#to_s ⇒ Object
205 206 207 |
# File 'lib/diva/type.rb', line 205 def to_s "#{model} #{name}" end |
#uri ⇒ Object
209 210 211 |
# File 'lib/diva/type.rb', line 209 def uri model.uri end |