Sha256: 4cd9d566afb8ad6d773b3f84c0c46927261399d5f9ea83be48d75ddbd8dd8e7d

Contents?: true

Size: 437 Bytes

Versions: 43

Compression:

Stored size: 437 Bytes

Contents

# frozen_string_literal: true

require 'json-schema'
require 'json'

module Twiglet
  class Validator
    attr_accessor :custom_error_handler

    def initialize(schema)
      @schema = JSON.parse(schema)
      @custom_error_handler = ->(e) { raise e }
    end

    def validate(message)
      JSON::Validator.validate!(@schema, message)
    rescue JSON::Schema::ValidationError => e
      custom_error_handler.call(e)
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
twiglet-3.14.0 lib/twiglet/validator.rb
twiglet-3.13.5 lib/twiglet/validator.rb
twiglet-3.13.4 lib/twiglet/validator.rb
twiglet-3.13.0 lib/twiglet/validator.rb
twiglet-3.12.0 lib/twiglet/validator.rb
twiglet-3.11.0 lib/twiglet/validator.rb
twiglet-3.10.0 lib/twiglet/validator.rb
twiglet-3.9.2 lib/twiglet/validator.rb
twiglet-3.9.1 lib/twiglet/validator.rb
twiglet-3.9.0 lib/twiglet/validator.rb
twiglet-3.8.0 lib/twiglet/validator.rb
twiglet-3.7.2 lib/twiglet/validator.rb
twiglet-3.7.1 lib/twiglet/validator.rb
twiglet-3.7.0 lib/twiglet/validator.rb
twiglet-3.6.6 lib/twiglet/validator.rb
twiglet-3.6.5 lib/twiglet/validator.rb
twiglet-3.6.4 lib/twiglet/validator.rb
twiglet-3.6.3 lib/twiglet/validator.rb
twiglet-3.6.2 lib/twiglet/validator.rb
twiglet-3.6.1 lib/twiglet/validator.rb