Class: Schemacop::Schema2

Inherits:
BaseSchema show all
Defined in:
lib/schemacop/schema2.rb

Direct Known Subclasses

Schema

Instance Attribute Summary

Attributes inherited from BaseSchema

#root

Instance Method Summary collapse

Methods inherited from BaseSchema

#invalid?, #valid?, #validate!

Constructor Details

#initialize(*args, **kwargs, &block) ⇒ Schema2

Returns a new instance of Schema2.



3
4
5
6
7
8
# File 'lib/schemacop/schema2.rb', line 3

def initialize(*args, **kwargs, &block)
  super()
  @root = V2::HashValidator.new do
    req :root, *args, **kwargs, &block
  end
end

Instance Method Details

#validate(data) ⇒ Schemacop::Collector

Validate data for the defined Schema

Parameters:

  • data

    The data to validate.

Returns:

  • (Schemacop::Collector)

    The object that collected errors throughout the validation.



15
16
17
18
19
20
# File 'lib/schemacop/schema2.rb', line 15

def validate(data)
  dupped_data = V2::Dupper.dup_data(data)
  collector = V2::Collector.new(dupped_data)
  root.fields[:root].validate({ root: data }, collector.ignore_next_segment)
  return collector
end