Class: Diva::Type::ModelType

Inherits:
MetaType show all
Defined in:
lib/diva/type.rb

Instance Attribute Summary collapse

Attributes inherited from MetaType

#name

Instance Method Summary collapse

Methods inherited from MetaType

#inspect

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

#modelObject (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
# File 'lib/diva/type.rb', line 146

def cast(value)
  raise Diva::InvalidTypeError, "The value is not a `#{model}'." unless value.is_a?(model)
  value
end

#to_sObject



151
152
153
# File 'lib/diva/type.rb', line 151

def to_s
  "#{model} #{name}"
end