class Oso::Polar::FFI::Polar

Wrapper class for Polar FFI pointer + operations.

Wrapper class for Polar FFI pointer + operations.

Constants

Rust

Attributes

enrich_message[RW]

Public Class Methods

create() click to toggle source

@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
release(ptr) click to toggle source
# File lib/oso/polar/ffi.rb, line 21
def self.release(ptr)
  Rust.free(ptr) unless ptr.null?
end

Public Instance Methods

clear_rules() click to toggle source

@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
enable_roles() click to toggle source

@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
handle_error() click to toggle source
# File lib/oso/polar/ffi/polar.rb, line 133
def handle_error
  raise FFI::Error.get(enrich_message)
end
load(src, filename: nil) click to toggle source

@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
new_id() click to toggle source

@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
new_query_from_str(str) click to toggle source

@param str [String] Query string. @return [FFI::Query] @raise [FFI::Error] if the FFI call returns an error.

# File lib/oso/polar/ffi/polar.rb, line 93
def new_query_from_str(str)
  query = Rust.new_query_from_str(self, str, 0)
  process_messages
  handle_error if query.null?

  query
end
new_query_from_term(term) click to toggle source

@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
next_inline_query() click to toggle source

@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
next_message() click to toggle source
# File lib/oso/polar/ffi/polar.rb, line 120
def next_message
  Rust.next_message(self)
end
process_messages() click to toggle source
# 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
register_constant(value, name:) click to toggle source

@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
validate_roles_config(config) click to toggle source

@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