Class: JsonValidation::Validators::PatternProperties
- Defined in:
- lib/json_validation/validators/pattern_properties.rb
Instance Attribute Summary
Attributes inherited from Validator
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_validators ⇒ Object
15 16 17 18 19 |
# File 'lib/json_validation/validators/pattern_properties.rb', line 15 def inner_validators @inner_validators ||= Hash[fragment['patternProperties'].map {|pattern, f| [pattern, build_validator(f)] }] end |
#validate(record) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/json_validation/validators/pattern_properties.rb', line 6 def validate(record) fragment['patternProperties'].keys.all? {|pattern| rx = Regexp.new(pattern) record.select {|k, v| rx.match(k)}.all? {|k, v| inner_validators[pattern].validate(v) } } end |