class Oso::Polar::FFI::Polar
Constants
- Rust
Attributes
Public Class Methods
@return [FFI::Polar] @raise [FFI::Error] if the FFI
call returns an error.
# File lib/oso/polar/ffi/polar.rb, line 33 def self.create polar = Rust.new handle_error if polar.null? polar end
# File lib/oso/polar/ffi.rb, line 21 def self.release(ptr) Rust.free(ptr) unless ptr.null? end
Public Instance Methods
@raise [FFI::Error] if the FFI
call returns an error.
# File lib/oso/polar/ffi/polar.rb, line 64 def clear_rules cleared = Rust.clear_rules(self) process_messages handle_error if cleared.zero? end
@raise [FFI::Error] if the FFI
call returns an error.
# File lib/oso/polar/ffi/polar.rb, line 41 def enable_roles result = Rust.enable_roles(self) process_messages handle_error if result.zero? end
# File lib/oso/polar/ffi/polar.rb, line 133 def handle_error raise FFI::Error.get(enrich_message) end
@param src [String] @param filename [String] @raise [FFI::Error] if the FFI
call returns an error.
# File lib/oso/polar/ffi/polar.rb, line 57 def load(src, filename: nil) loaded = Rust.load(self, src, filename) process_messages handle_error if loaded.zero? end
@return [Integer] @raise [FFI::Error] if the FFI
call returns an error.
# File lib/oso/polar/ffi/polar.rb, line 81 def new_id id = Rust.new_id(self) # TODO(gj): I don't think this error check is correct. If getting a new ID fails on the # Rust side, it'll probably surface as a panic (e.g., the KB lock is poisoned). handle_error if id.zero? id end
@param term [Hash<String, Object>] @return [FFI::Query] @raise [FFI::Error] if the FFI
call returns an error.
# File lib/oso/polar/ffi/polar.rb, line 104 def new_query_from_term(term) query = Rust.new_query_from_term(self, JSON.dump(term), 0) process_messages handle_error if query.null? query end
@return [FFI::Query] if there are remaining inline queries. @return [nil] if there are no remaining inline queries. @raise [FFI::Error] if the FFI
call returns an error.
# File lib/oso/polar/ffi/polar.rb, line 73 def next_inline_query query = Rust.next_inline_query(self, 0) process_messages query.null? ? nil : query end
# File lib/oso/polar/ffi/polar.rb, line 120 def next_message Rust.next_message(self) end
# File lib/oso/polar/ffi/polar.rb, line 124 def process_messages loop do message = next_message break if message.null? message.process(enrich_message) end end
@param name [String] @param value [Hash<String, Object>] @raise [FFI::Error] if the FFI
call returns an error.
# File lib/oso/polar/ffi/polar.rb, line 115 def register_constant(value, name:) registered = Rust.register_constant(self, name, JSON.dump(value)) handle_error if registered.zero? end
@raise [FFI::Error] if the FFI
call returns an error.
# File lib/oso/polar/ffi/polar.rb, line 48 def validate_roles_config(config) result = Rust.validate_roles_config(self, JSON.dump(config)) process_messages handle_error if result.zero? end