class JSON::Validator

Public Class Methods

clear_errors() click to toggle source
# File lib/aspace_client/json_schema_concurrency_fix.rb, line 26
def clear_errors
  Thread.current[:jsonschema_errors] = []
end
validation_error(error) click to toggle source
# File lib/aspace_client/json_schema_concurrency_fix.rb, line 30
def validation_error(error)
  Thread.current[:jsonschema_errors] << error
end
validation_errors() click to toggle source
# File lib/aspace_client/json_schema_concurrency_fix.rb, line 34
def validation_errors
  Thread.current[:jsonschema_errors] or []
end

Public Instance Methods

serialize(schema) click to toggle source

Plus one bonus: don’t use MultiJson here.

# File lib/aspace_client/json_schema_concurrency_fix.rb, line 41
def serialize schema
  # if defined?(MultiJson)
  #   MultiJson.respond_to?(:dump) ? MultiJson.dump(schema) : MultiJson.encode(schema)
  # else
  #   @@serializer.call(schema)
  # end

  ASUtils.to_json(schema)
end
validate() click to toggle source

Run a simple true/false validation of data against a schema

# File lib/aspace_client/json_schema_concurrency_fix.rb, line 9
def validate()
  begin
    Validator.clear_errors
    @base_schema.validate(@data,[],@validation_options)
    Validator.clear_cache
    if @options[:errors_as_objects]
      self.class.validation_errors.map{|e| e.to_hash}
    else
      self.class.validation_errors.map{|e| e.to_string}
    end
  rescue JSON::Schema::ValidationError
    Validator.clear_cache
    raise $!
  end
end