Class: JsonValidation::Validators::Type

Inherits:
Validator
  • Object
show all
Defined in:
lib/json_validation/validators/type.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

#validate(record) ⇒ Object



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

def validate(record)
  types = Array(fragment['type'])
  types.any? {|type| 
    klasses = JsonValidation::TYPES_TO_CLASSES.fetch(type.to_sym)
    klasses.any? {|klass| record.is_a?(klass)}
  }
end