Sha256: 7e848b87e1e8ab91af1f125453e8237e78467065d609fda3bbde68cb1c965773

Contents?: true

Size: 649 Bytes

Versions: 7

Compression:

Stored size: 649 Bytes

Contents

# frozen_string_literal: true

module RustyJSONSchema

  # Handles release of the pointer automatically
  # with Ruby GC. This way we can intialize validator
  # in Rust, and hold a reference in Ruby.
  #
  class Validator < FFI::AutoPointer

    # Custom GC flow for our validator, freeing
    # the object within Rust
    #
    def self.release(pointer)
      Binding.free(pointer)
    end

    # Simple validation without actual error messages
    #
    def valid?(event)
      Binding.is_valid(self, RustyJSONSchema.dump(event))
    end

    def validate(event)
      Binding.validate(self, RustyJSONSchema.dump(event)).to_a
    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rusty_json_schema-0.6.1 lib/rusty_json_schema/validator.rb
rusty_json_schema-0.5.0 lib/rusty_json_schema/validator.rb
rusty_json_schema-0.3.2 lib/rusty_json_schema/validator.rb
rusty_json_schema-0.3.1 lib/rusty_json_schema/validator.rb
rusty_json_schema-0.3.0-x86_64-linux lib/rusty_json_schema/validator.rb
rusty_json_schema-0.3.0-x86_64-darwin-19 lib/rusty_json_schema/validator.rb
rusty_json_schema-0.2.0 lib/rusty_json_schema/validator.rb