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
230 231 232 233 |
# File 'lib/diva/type.rb', line 230 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
235 236 237 |
# File 'lib/diva/type.rb', line 235 def dump_for_json(value) value.to_a.map(&@type.method(:dump_for_json)) end |
#recommendation_point(values) ⇒ Object
226 227 228 |
# File 'lib/diva/type.rb', line 226 def recommendation_point(values) values.is_a?(Enumerable) && values.all? { |v| @type.recommendation_point(v) } && 0 end |
#schema ⇒ Object
243 244 245 |
# File 'lib/diva/type.rb', line 243 def schema @schema ||= { array: @type.schema }.freeze end |
#to_s ⇒ Object
239 240 241 |
# File 'lib/diva/type.rb', line 239 def to_s "Array of #{@type}" end |