Class: Diva::Type::ArrayType

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

Instance Attribute Summary

Attributes inherited from MetaType

#name

Instance Method Summary collapse

Methods inherited from MetaType

#inspect

Constructor Details

#initialize(type) ⇒ ArrayType

Returns a new instance of ArrayType.



174
175
176
177
178
# File 'lib/diva/type.rb', line 174

def initialize(type)
  type = Diva::Type(type)
  super("#{type.name}_array")
  @type = type
end

Instance Method Details

#cast(value) ⇒ Object



180
181
182
183
# File 'lib/diva/type.rb', line 180

def cast(value)
  raise Diva::InvalidTypeError, "The value is not a `#{name}'." unless value.is_a?(Enumerable)
  value.to_a.map(&@type.method(:cast))
end

#dump_for_json(value) ⇒ Object



185
186
187
# File 'lib/diva/type.rb', line 185

def dump_for_json(value)
  value.to_a.map(&@type.method(:dump_for_json))
end

#to_sObject



189
190
191
# File 'lib/diva/type.rb', line 189

def to_s
  "Array of #{@type.to_s}"
end