Class: Diva::Type::ArrayType
Instance Attribute Summary
Attributes inherited from MetaType
Instance Method Summary collapse
- #cast(value) ⇒ Object
- #dump_for_json(value) ⇒ Object
-
#initialize(type) ⇒ ArrayType
constructor
A new instance of ArrayType.
- #recommendation_point(values) ⇒ Object
- #schema ⇒ Object
- #to_s ⇒ Object
Methods inherited from MetaType
Constructor Details
Instance Method Details
#cast(value) ⇒ Object
225 226 227 228 |
# File 'lib/diva/type.rb', line 225 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
230 231 232 |
# File 'lib/diva/type.rb', line 230 def dump_for_json(value) value.to_a.map(&@type.method(:dump_for_json)) end |
#recommendation_point(values) ⇒ Object
221 222 223 |
# File 'lib/diva/type.rb', line 221 def recommendation_point(values) values.is_a?(Enumerable) && values.all?{|v| @type.recommendation_point(v) } && 0 end |
#schema ⇒ Object
238 239 240 |
# File 'lib/diva/type.rb', line 238 def schema @schema ||= { array: @type.schema }.freeze end |
#to_s ⇒ Object
234 235 236 |
# File 'lib/diva/type.rb', line 234 def to_s "Array of #{@type.to_s}" end |