Class: RustyJSONSchema::Validator
- Inherits:
-
FFI::AutoPointer
- Object
- FFI::AutoPointer
- RustyJSONSchema::Validator
- 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
-
.release(pointer) ⇒ Object
Custom GC flow for our validator, freeing the object within Rust.
Instance Method Summary collapse
-
#valid?(event) ⇒ Boolean
Simple validation without actual error messages.
-
#validate(event) ⇒ Object
Full validation and error messages.
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
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 |