Class: StrongJSON::Type::Array

Inherits:
Object
  • Object
show all
Defined in:
lib/strong_json/type.rb

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Array

Returns a new instance of Array.



56
57
58
# File 'lib/strong_json/type.rb', line 56

def initialize(type)
  @type = type
end

Instance Method Details

#coerce(value, path: []) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/strong_json/type.rb', line 60

def coerce(value, path: [])
  if value.is_a?(::Array)
    value.map.with_index do |v, i|
      @type.coerce(v, path: path+[i])
    end
  else
    raise Error.new(path: path, type: self, value: value)
  end
end

#to_sObject



70
71
72
# File 'lib/strong_json/type.rb', line 70

def to_s
  "array(#{@type})"
end