Class: JsonValidation::Validators::Properties

Inherits:
Validator
  • Object
show all
Defined in:
lib/json_validation/validators/properties.rb

Instance Attribute Summary

Attributes inherited from Validator

#base_uri, #fragment

Instance Method Summary collapse

Methods inherited from Validator

#build_validator, #build_validator_with_new_base_uri, #initialize, type

Constructor Details

This class inherits a constructor from JsonValidation::Validators::Validator

Instance Method Details

#inner_validatorsObject



16
17
18
19
20
# File 'lib/json_validation/validators/properties.rb', line 16

def inner_validators
  @inner_validators ||= Hash[fragment['properties'].map {|k, f|
    [k, build_validator(f)]
  }]
end

#validate(record) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/json_validation/validators/properties.rb', line 6

def validate(record)
  fragment['properties'].keys.all? {|key|
    if record[key]
      inner_validators[key].validate(record[key])
    else
      true
    end
  }
end