Class: Oso::Polar::FFI::Query
- Inherits:
-
FFI::AutoPointer
- Object
- FFI::AutoPointer
- Oso::Polar::FFI::Query
- Defined in:
- lib/oso/polar/ffi.rb,
lib/oso/polar/ffi/query.rb
Overview
Wrapper class for Query FFI pointer + operations.
Instance Attribute Summary collapse
-
#enrich_message ⇒ Object
Returns the value of attribute enrich_message.
Class Method Summary collapse
Instance Method Summary collapse
- #application_error(message) ⇒ Object
- #bind(name, value) ⇒ Object
- #call_result(value, call_id:) ⇒ Object
-
#check_result(res) ⇒ Object
Unwrap the result by (a) extracting the pointers for result and error, (b) freeing the result pointers, and then © either returning the result pointer, or constructing and raising the error.
- #debug_command(cmd) ⇒ Object
- #next_event ⇒ ::Oso::Polar::QueryEvent
- #next_message ⇒ Object
- #process_message(message, enrich_message) ⇒ Object
- #process_messages ⇒ Object
- #question_result(result, call_id:) ⇒ Object
- #source ⇒ String
- #zero? ⇒ Boolean
Instance Attribute Details
#enrich_message ⇒ Object
Returns the value of attribute enrich_message.
10 11 12 |
# File 'lib/oso/polar/ffi/query.rb', line 10 def @enrich_message end |
Class Method Details
.release(ptr) ⇒ Object
36 37 38 |
# File 'lib/oso/polar/ffi.rb', line 36 def self.release(ptr) Rust.free(ptr) unless ptr.null? end |
Instance Method Details
#application_error(message) ⇒ Object
56 57 58 59 |
# File 'lib/oso/polar/ffi/query.rb', line 56 def application_error() res = Rust.application_error(self, ) check_result res end |
#bind(name, value) ⇒ Object
71 72 73 74 |
# File 'lib/oso/polar/ffi/query.rb', line 71 def bind(name, value) res = Rust.bind(self, name, JSON.dump(value)) check_result res end |
#call_result(value, call_id:) ⇒ Object
40 41 42 43 |
# File 'lib/oso/polar/ffi/query.rb', line 40 def call_result(value, call_id:) res = Rust.call_result(self, call_id, JSON.dump(value)) check_result res end |
#check_result(res) ⇒ Object
Unwrap the result by (a) extracting the pointers for result and error, (b) freeing the result pointers, and then © either returning the result pointer, or constructing and raising the error.
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/oso/polar/ffi/query.rb', line 116 def check_result(res) result = res[:result] error = res[:error] Rust.result_free(res) raise 'internal error: both result and error pointers are not null' if !error.null? && !result.zero? raise FFI::Error.get(error, ) unless error.null? result end |
#debug_command(cmd) ⇒ Object
31 32 33 34 35 |
# File 'lib/oso/polar/ffi/query.rb', line 31 def debug_command(cmd) res = Rust.debug_command(self, cmd) check_result res end |
#next_event ⇒ ::Oso::Polar::QueryEvent
63 64 65 66 67 68 69 |
# File 'lib/oso/polar/ffi/query.rb', line 63 def next_event event = Rust.next_event(self) event = check_result event ::Oso::Polar::QueryEvent.new(JSON.parse(event.to_s)) end |
#next_message ⇒ Object
76 77 78 |
# File 'lib/oso/polar/ffi/query.rb', line 76 def check_result Rust.(self) end |
#process_message(message, enrich_message) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/oso/polar/ffi/query.rb', line 80 def (, ) = JSON.parse(.to_s) kind = ['kind'] msg = ['msg'] msg = .call(msg) case kind when 'Print' puts(msg) when 'Warning' warn(format('[warning] %<msg>s', msg: msg)) end end |
#process_messages ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/oso/polar/ffi/query.rb', line 94 def loop do = break if .null? (, ) end end |
#question_result(result, call_id:) ⇒ Object
48 49 50 51 52 |
# File 'lib/oso/polar/ffi/query.rb', line 48 def question_result(result, call_id:) result = result ? 1 : 0 res = Rust.question_result(self, call_id, result) check_result res end |
#source ⇒ String
105 106 107 108 109 110 |
# File 'lib/oso/polar/ffi/query.rb', line 105 def source res = Rust.source(self) res = check_result res res.to_s end |
#zero? ⇒ Boolean
32 33 34 |
# File 'lib/oso/polar/ffi.rb', line 32 def zero? null? end |