class Oso::Polar::FFI::Query

Wrapper class for Query FFI pointer + operations.

Wrapper class for Query FFI pointer + operations.

Constants

Rust

Attributes

enrich_message[RW]

Public Class Methods

release(ptr) click to toggle source
# File lib/oso/polar/ffi.rb, line 27
def self.release(ptr)
  Rust.free(ptr) unless ptr.null?
end

Public Instance Methods

application_error(message) click to toggle source

@param result [Boolean] @param call_id [Integer] @raise [FFI::Error] if the FFI call returns an error.

# File lib/oso/polar/ffi/query.rb, line 55
def application_error(message)
  res = Rust.application_error(self, message)
  handle_error if res.zero?
end
call_result(result, call_id:) click to toggle source

@param result [String] @param call_id [Integer] @raise [FFI::Error] if the FFI call returns an error.

# File lib/oso/polar/ffi/query.rb, line 38
def call_result(result, call_id:)
  res = Rust.call_result(self, call_id, result)
  handle_error if res.zero?
end
debug_command(cmd) click to toggle source

@param cmd [String] @raise [FFI::Error] if the FFI call returns an error.

# File lib/oso/polar/ffi/query.rb, line 29
def debug_command(cmd)
  res = Rust.debug_command(self, cmd)
  process_messages
  handle_error if res.zero?
end
handle_error() click to toggle source
# File lib/oso/polar/ffi/query.rb, line 92
def handle_error
  raise FFI::Error.get(enrich_message)
end
next_event() click to toggle source

@return [::Oso::Polar::QueryEvent] @raise [FFI::Error] if the FFI call returns an error.

# File lib/oso/polar/ffi/query.rb, line 62
def next_event
  event = Rust.next_event(self)
  process_messages
  handle_error if event.null?

  ::Oso::Polar::QueryEvent.new(JSON.parse(event.to_s))
end
next_message() click to toggle source
# File lib/oso/polar/ffi/query.rb, line 70
def next_message
  Rust.next_message(self)
end
process_messages() click to toggle source
# File lib/oso/polar/ffi/query.rb, line 74
def process_messages
  loop do
    message = next_message
    break if message.null?

    message.process(enrich_message)
  end
end
question_result(result, call_id:) click to toggle source

@param result [Boolean] @param call_id [Integer] @raise [FFI::Error] if the FFI call returns an error.

# File lib/oso/polar/ffi/query.rb, line 46
def question_result(result, call_id:)
  result = result ? 1 : 0
  res = Rust.question_result(self, call_id, result)
  handle_error if res.zero?
end
source() click to toggle source

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

# File lib/oso/polar/ffi/query.rb, line 85
def source
  res = Rust.source(self)
  handle_error if res.null?

  res.to_s
end