Class: VCAP::JsonSchema::ArraySchema

Inherits:
BaseSchema show all
Defined in:
lib/vcap/json_schema.rb

Overview

Checks that supplied value is an array, and each value in the array validates

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ ArraySchema

Returns a new instance of ArraySchema.

Raises:

  • (ArgumentError)


87
88
89
90
# File 'lib/vcap/json_schema.rb', line 87

def initialize(schema)
  raise ArgumentError, "You must supply a schema, #{schema.class} given" unless schema.kind_of?(BaseSchema)
  @item_schema = schema
end

Instance Attribute Details

#item_schemaObject

Returns the value of attribute item_schema.



85
86
87
# File 'lib/vcap/json_schema.rb', line 85

def item_schema
  @item_schema
end

Instance Method Details

#validate(dec_json) ⇒ Object

Raises:



92
93
94
95
96
97
# File 'lib/vcap/json_schema.rb', line 92

def validate(dec_json)
  raise TypeError, "Expected instance of Array, #{dec_json.class} given" unless dec_json.kind_of?(Array)
  for v in dec_json
    @item_schema.validate(v)
  end
end