Sha256: be576230b84997105805781185e71e65105b673a2d2e110e9c3afbf09ee2c522

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

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
    #
    # ## Examples
    #
    #     validator = RustyJSONSchema.build(json_schema)
    #     validator.valid?(event)
    #     # => false|true
    #
    def valid?(event)
      Binding.is_valid(self, RustyJSONSchema.dump(event))
    end

    # Full validation and error messages
    #
    # ## Examples
    #
    #     validator = RustyJSONSchema.build(json_schema)
    #     validator.validate(event)
    #     # => [
    #     #   'path "/foo": "rusty" is not a "number"',
    #     #   ...
    #     # ]
    #
    def validate(event)
      Binding.validate(self, RustyJSONSchema.dump(event)).to_a
    end

  end

end

Version data entries

6 entries across 6 versions & 4 rubygems

Version Path
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/rusty_json_schema-0.15.0/lib/rusty_json_schema/validator.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/rusty_json_schema-0.15.0/lib/rusty_json_schema/validator.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/rusty_json_schema-0.15.0/lib/rusty_json_schema/validator.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/rusty_json_schema-0.15.0/lib/rusty_json_schema/validator.rb
rusty_json_schema-0.15.0 lib/rusty_json_schema/validator.rb
rusty_json_schema-0.9.0 lib/rusty_json_schema/validator.rb