Class: Schemacop::HashValidator

Inherits:
NodeSupportingField show all
Defined in:
lib/schemacop/validator/hash_validator.rb

Instance Attribute Summary

Attributes inherited from NodeSupportingField

#fields

Attributes inherited from Node

#options

Instance Method Summary collapse

Methods inherited from NodeSupportingField

#initialize, #opt!, #opt?, #req!, #req?

Methods inherited from NodeWithBlock

block_method, #exec_block

Methods inherited from Node

build, class_matches?, clear_klasses, clear_symbols, #exec_block, #initialize, klass, option, #option, #option?, register, #resolve_type_klass, symbol, symbol_matches?, #type_filter_matches?, #type_label, type_matches?, #type_matches?

Constructor Details

This class inherits a constructor from Schemacop::NodeSupportingField

Instance Method Details

#validate(data, collector) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/schemacop/validator/hash_validator.rb', line 5

def validate(data, collector)
  super

  allowed_fields = @fields.keys
  obsolete_keys = data.keys - allowed_fields

  collector.error "Obsolete keys: #{obsolete_keys.inspect}." if obsolete_keys.any?

  @fields.values.each do |field|
    field.validate(data, collector)
  end
end