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.6.0 lib/twiglet/validator.rb
twiglet-3.5.4 lib/twiglet/validator.rb
twiglet-3.5.2 lib/twiglet/validator.rb
twiglet-3.5.1 lib/twiglet/validator.rb
twiglet-3.5.0 lib/twiglet/validator.rb
twiglet-3.4.9 lib/twiglet/validator.rb
twiglet-3.4.8 lib/twiglet/validator.rb
twiglet-3.4.3 lib/twiglet/validator.rb
twiglet-3.4.2 lib/twiglet/validator.rb
twiglet-3.4.1 lib/twiglet/validator.rb
twiglet-3.4.0 lib/twiglet/validator.rb
twiglet-3.3.7 lib/twiglet/validator.rb
twiglet-3.3.6 lib/twiglet/validator.rb
twiglet-3.3.5 lib/twiglet/validator.rb
twiglet-3.3.4 lib/twiglet/validator.rb
twiglet-3.3.3 lib/twiglet/validator.rb
twiglet-3.3.2 lib/twiglet/validator.rb
twiglet-3.3.0 lib/twiglet/validator.rb
twiglet-3.2.5 lib/twiglet/validator.rb
twiglet-3.2.4 lib/twiglet/validator.rb