Class: JSON::Schema::CustomFormat

Inherits:
FormatAttribute show all
Defined in:
lib/json-schema/attributes/formats/custom.rb

Constant Summary

Constants inherited from Attribute

Attribute::TYPE_CLASS_MAPPINGS

Instance Method Summary collapse

Methods inherited from FormatAttribute

validate

Methods inherited from Attribute

build_fragment, data_valid_for_type?, type_of_data, validate, validation_error, validation_errors

Constructor Details

#initialize(validation_proc) ⇒ CustomFormat

Returns a new instance of CustomFormat.



7
8
9
# File 'lib/json-schema/attributes/formats/custom.rb', line 7

def initialize(validation_proc)
  @validation_proc = validation_proc
end

Instance Method Details

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



11
12
13
14
15
16
17
18
# File 'lib/json-schema/attributes/formats/custom.rb', line 11

def validate(current_schema, data, fragments, processor, validator, options = {})
  begin
    @validation_proc.call data
  rescue JSON::Schema::CustomFormatError => e
    message = "The property '#{self.class.build_fragment(fragments)}' #{e.message}"
    self.class.validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
  end
end