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
Returns a new instance of ModelType.
141 142 143 144 |
# File 'lib/diva/type.rb', line 141 def initialize(model, *rest, &cast) super(:model, *rest) @model = model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
140 141 142 |
# File 'lib/diva/type.rb', line 140 def model @model end |
Instance Method Details
#cast(value) ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/diva/type.rb', line 146 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
157 158 159 |
# File 'lib/diva/type.rb', line 157 def to_s "#{model} #{name}" end |