Sha256: b23d2da4f2517f55814319550855952d9d8aaf71ed026402dc0d82c47ac79d7c
Contents?: true
Size: 512 Bytes
Versions: 4
Compression:
Stored size: 512 Bytes
Contents
# frozen_string_literal: true require 'json-schema' require 'json' module Twiglet class Validator attr_accessor :custom_error_handler def initialize(schema) @schema = schema @custom_error_handler = ->(e) { raise e } end def self.from_file(file_path) new(JSON.parse(File.read(file_path))) 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
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
twiglet-3.1.3 | lib/twiglet/validator.rb |
twiglet-3.1.2 | lib/twiglet/validator.rb |
twiglet-3.1.1 | lib/twiglet/validator.rb |
twiglet-3.1.0 | lib/twiglet/validator.rb |