class JSON::Schema::Attribute

Constants

TYPE_CLASS_MAPPINGS

Public Class Methods

build_fragment(fragments) click to toggle source
# File lib/json-schema/attribute.rb, line 9
def self.build_fragment(fragments)
  "#/#{fragments.join('/')}"
end
data_valid_for_type?(data, type) click to toggle source
# File lib/json-schema/attribute.rb, line 37
def self.data_valid_for_type?(data, type)
  valid_classes = TYPE_CLASS_MAPPINGS.fetch(type) { return true }
  Array(valid_classes).any? { |c| data.is_a?(c) }
end
type_of_data(data) click to toggle source

Lookup Schema type of given class instance

# File lib/json-schema/attribute.rb, line 43
def self.type_of_data(data)
  type, _ = TYPE_CLASS_MAPPINGS.map { |k,v| [k,v] }.sort_by { |(_, v)|
    -Array(v).map { |klass| klass.ancestors.size }.max
  }.find { |(_, v)|
    Array(v).any? { |klass| data.kind_of?(klass) }
  }
  type
end
validate(current_schema, data, fragments, processor, validator, options = {}) click to toggle source
# File lib/json-schema/attribute.rb, line 6
def self.validate(current_schema, data, fragments, processor, validator, options = {})
end
validation_error(processor, message, fragments, current_schema, failed_attribute, record_errors) click to toggle source
# File lib/json-schema/attribute.rb, line 13
def self.validation_error(processor, message, fragments, current_schema, failed_attribute, record_errors)
  error = ValidationError.new(message, fragments, failed_attribute, current_schema)
  if record_errors
    processor.validation_error(error)
  else
    raise error
  end
end
validation_errors(validator) click to toggle source
# File lib/json-schema/attribute.rb, line 22
def self.validation_errors(validator)
  validator.validation_errors
end