Class: RustyJSONSchema::Validator

Inherits:
FFI::AutoPointer
  • Object
show all
Defined in:
lib/rusty_json_schema/validator.rb

Overview

Handles release of the pointer automatically with Ruby GC. This way we can intialize validator in Rust, and hold a reference in Ruby.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.release(pointer) ⇒ Object

Custom GC flow for our validator, freeing the object within Rust



14
15
16
# File 'lib/rusty_json_schema/validator.rb', line 14

def self.release(pointer)
  Binding.free(pointer)
end

Instance Method Details

#valid?(event) ⇒ Boolean

Simple validation without actual error messages

## Examples

validator = RustyJSONSchema.build(json_schema)
validator.valid?(event)
# => false|true

Returns:

  • (Boolean)


26
27
28
# File 'lib/rusty_json_schema/validator.rb', line 26

def valid?(event)
  Binding.is_valid(self, RustyJSONSchema.dump(event))
end

#validate(event) ⇒ Object

Full validation and error messages

## Examples

validator = RustyJSONSchema.build(json_schema)
validator.validate(event)
# => [
#   'path "/foo": "rusty" is not a "number"',
#   ...
# ]


41
42
43
# File 'lib/rusty_json_schema/validator.rb', line 41

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