Class: JSON::Schema::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/json-schema/attribute.rb

Constant Summary collapse

TYPE_CLASS_MAPPINGS =
{
  "string" => String,
  "number" => Numeric,
  "integer" => Integer,
  "boolean" => [TrueClass, FalseClass],
  "object" => Hash,
  "array" => Array,
  "null" => NilClass,
  "any" => Object
}

Class Method Summary collapse

Class Method Details

.build_fragment(fragments) ⇒ Object



9
10
11
# File 'lib/json-schema/attribute.rb', line 9

def self.build_fragment(fragments)
  "#/#{fragments.join('/')}"
end

.data_valid_for_type?(data, type) ⇒ Boolean



37
38
39
40
# 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

.validate(current_schema, data, fragments, processor, validator, options = {}) ⇒ Object



6
7
# 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) ⇒ Object



13
14
15
16
17
18
19
20
# 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) ⇒ Object



22
23
24
# File 'lib/json-schema/attribute.rb', line 22

def self.validation_errors(validator)
  validator.validation_errors
end