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.
- #to_s ⇒ Object
Methods inherited from MetaType
Constructor Details
#initialize(model, *rest, &cast) ⇒ ModelType
152 153 154 155 |
# File 'lib/diva/type.rb', line 152 def initialize(model, *rest, &cast) super(:model, *rest) @model = model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
151 152 153 |
# File 'lib/diva/type.rb', line 151 def model @model end |
Instance Method Details
#cast(value) ⇒ Object
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/diva/type.rb', line 157 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 |
#to_s ⇒ Object
168 169 170 |
# File 'lib/diva/type.rb', line 168 def to_s "#{model} #{name}" end |