Class: Oso::Polar::FFI::Polar
- Inherits:
-
FFI::AutoPointer
- Object
- FFI::AutoPointer
- Oso::Polar::FFI::Polar
- Defined in:
- lib/oso/polar/ffi.rb,
lib/oso/polar/ffi/polar.rb
Overview
Wrapper class for Polar FFI pointer + operations.
Instance Attribute Summary collapse
-
#enrich_message ⇒ Object
rubocop:disable Metrics/ClassLength.
Class Method Summary collapse
Instance Method Summary collapse
- #build_data_filter(types, partials, variable, class_tag) ⇒ Object
- #build_filter_plan(types, partials, variable, class_tag) ⇒ Object
- #check_result(res) ⇒ Object
- #clear_rules ⇒ Object
- #load(sources) ⇒ Object
- #new_id ⇒ Integer
- #new_query_from_str(str) ⇒ FFI::Query
- #new_query_from_term(term) ⇒ FFI::Query
- #next_inline_query ⇒ FFI::Query?
- #next_message ⇒ Object
- #process_message(message, enrich_message) ⇒ Object
- #process_messages ⇒ Object
- #register_constant(value, name:) ⇒ Object
- #register_mro(name, mro) ⇒ Object
- #zero? ⇒ Boolean
Instance Attribute Details
#enrich_message ⇒ Object
rubocop:disable Metrics/ClassLength
10 11 12 |
# File 'lib/oso/polar/ffi/polar.rb', line 10 def @enrich_message end |
Class Method Details
.create ⇒ FFI::Polar
45 46 47 |
# File 'lib/oso/polar/ffi/polar.rb', line 45 def self.create Rust.new end |
.release(ptr) ⇒ Object
31 32 33 |
# File 'lib/oso/polar/ffi.rb', line 31 def self.release(ptr) Rust.free(ptr) unless ptr.null? end |
Instance Method Details
#build_data_filter(types, partials, variable, class_tag) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/oso/polar/ffi/polar.rb', line 59 def build_data_filter(types, partials, variable, class_tag) types = JSON.dump(types) partials = JSON.dump(partials) plan = Rust.build_data_filter(self, types, partials, variable, class_tag) plan = check_result plan # TODO(gw) more error checking? JSON.parse plan.to_s end |
#build_filter_plan(types, partials, variable, class_tag) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/oso/polar/ffi/polar.rb', line 49 def build_filter_plan(types, partials, variable, class_tag) types = JSON.dump(types) partials = JSON.dump(partials) plan = Rust.build_filter_plan(self, types, partials, variable, class_tag) plan = check_result plan # TODO(gw) more error checking? JSON.parse plan.to_s end |
#check_result(res) ⇒ Object
159 160 161 162 163 164 165 166 167 168 |
# File 'lib/oso/polar/ffi/polar.rb', line 159 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 |
#clear_rules ⇒ Object
78 79 80 81 82 |
# File 'lib/oso/polar/ffi/polar.rb', line 78 def clear_rules cleared = Rust.clear_rules(self) check_result cleared end |
#load(sources) ⇒ Object
71 72 73 74 75 |
# File 'lib/oso/polar/ffi/polar.rb', line 71 def load(sources) loaded = Rust.load(self, JSON.dump(sources)) check_result loaded end |
#new_id ⇒ Integer
95 96 97 |
# File 'lib/oso/polar/ffi/polar.rb', line 95 def new_id Rust.new_id(self) end |
#new_query_from_str(str) ⇒ FFI::Query
102 103 104 105 106 |
# File 'lib/oso/polar/ffi/polar.rb', line 102 def new_query_from_str(str) query = Rust.new_query_from_str(self, str, 0) check_result query end |
#new_query_from_term(term) ⇒ FFI::Query
111 112 113 114 115 |
# File 'lib/oso/polar/ffi/polar.rb', line 111 def new_query_from_term(term) query = Rust.new_query_from_term(self, JSON.dump(term), 0) check_result query end |
#next_inline_query ⇒ FFI::Query?
87 88 89 90 91 |
# File 'lib/oso/polar/ffi/polar.rb', line 87 def next_inline_query query = Rust.next_inline_query(self, 0) query.null? ? nil : query end |
#next_message ⇒ Object
133 134 135 |
# File 'lib/oso/polar/ffi/polar.rb', line 133 def check_result Rust.(self) end |
#process_message(message, enrich_message) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/oso/polar/ffi/polar.rb', line 137 def (, ) = JSON.parse(.to_s) kind = ['kind'] msg = .call(['msg']) case kind when 'Print' puts(msg) when 'Warning' warn(format('[warning] %<msg>s', msg: msg)) end end |
#process_messages ⇒ Object
150 151 152 153 154 155 156 157 |
# File 'lib/oso/polar/ffi/polar.rb', line 150 def loop do = break if .null? (, ) end end |
#register_constant(value, name:) ⇒ Object
120 121 122 123 |
# File 'lib/oso/polar/ffi/polar.rb', line 120 def register_constant(value, name:) registered = Rust.register_constant(self, name, JSON.dump(value)) check_result registered end |
#register_mro(name, mro) ⇒ Object
128 129 130 131 |
# File 'lib/oso/polar/ffi/polar.rb', line 128 def register_mro(name, mro) registered = Rust.register_mro(self, name, JSON.dump(mro)) check_result registered end |
#zero? ⇒ Boolean
27 28 29 |
# File 'lib/oso/polar/ffi.rb', line 27 def zero? null? end |