oso-oso 0.14.0 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2aee8d8308beb5cb906dff373ef43f8a90c5d3f
4
- data.tar.gz: a121f6f4b7534f53934f49aab4e634cbbbe7f0db
3
+ metadata.gz: e611289b05e0398183cb6e7f29929b2854b1aaad
4
+ data.tar.gz: bd8af76c1433c16193b4cf2587cc5ca9f953c5b8
5
5
  SHA512:
6
- metadata.gz: 6cb9212a01eaa50005a5d3923632741cfbbfff8c28c42a3c7f30b2cf6bf6aeba58fbe4f4c87ff3ccb43deb21dfd2db6e3f95ce7aded5996fe2eb6cb74d5de162
7
- data.tar.gz: ef8ec9735a3aba0c18d9da63ea0fda8b36e1d6c6cd3306611b1b126d6587f1381b2e558680058c4c926ed9d736b7fa21c96f92ae179b0df485d24ea3bd1c1791
6
+ metadata.gz: 6778dedbfe11bb27219ed96712e3e93e79d3187455aad86040764e25b34079a4645ec16de0afed876faa88b290e58fad7e22ccd2ee6aaa61529bd1f9b6231a28
7
+ data.tar.gz: d21fda13edd7176ecc3dad96258f57f19f51b3114ee02c1fb844277befd0abf9a8cfb035df0593a49977a884aa2bc3fbfd6734cc547be0ef5093d149f866c8d7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oso-oso (0.14.0)
4
+ oso-oso (0.14.1)
5
5
  ffi (~> 1.0)
6
6
 
7
7
  GEM
Binary file
Binary file
Binary file
@@ -149,6 +149,33 @@ module Oso
149
149
  raise PolarRuntimeError, "Error constructing instance of #{cls_name}: #{e}"
150
150
  end
151
151
 
152
+ OPS = {
153
+ 'Lt' => :<,
154
+ 'Gt' => :>,
155
+ 'Eq' => :==,
156
+ 'Geq' => :>=,
157
+ 'Leq' => :<=,
158
+ 'Neq' => :!=
159
+ }.freeze
160
+
161
+ # Compare two values
162
+ #
163
+ # @param op [String] operation to perform.
164
+ # @param args [Array<Object>] left and right args to operation.
165
+ # @raise [PolarRuntimeError] if operation fails or is unsupported.
166
+ # @return [Boolean]
167
+ def operator(operation, args)
168
+ left, right = args
169
+ op = OPS[operation]
170
+ raise PolarRuntimeError, "Unsupported external operation '#{left.class} #{operation} #{right.class}'" if op.nil?
171
+
172
+ begin
173
+ left.__send__ op, right
174
+ rescue StandardError
175
+ raise PolarRuntimeError, "External operation '#{left.class} #{operation} #{right.class}' failed."
176
+ end
177
+ end
178
+
152
179
  # Check if the left class is more specific than the right class
153
180
  # with respect to the given instance.
154
181
  #
@@ -174,17 +201,6 @@ module Oso
174
201
  instance.is_a? cls
175
202
  end
176
203
 
177
- # Check if two instances unify
178
- #
179
- # @param left_instance_id [Integer]
180
- # @param right_instance_id [Integer]
181
- # @return [Boolean]
182
- def unify?(left_instance_id, right_instance_id)
183
- left_instance = get_instance(left_instance_id)
184
- right_instance = get_instance(right_instance_id)
185
- left_instance == right_instance
186
- end
187
-
188
204
  # Turn a Ruby value into a Polar term that's ready to be sent across the
189
205
  # FFI boundary.
190
206
  #
@@ -146,11 +146,6 @@ module Oso
146
146
  class_tag = event.data['class_tag']
147
147
  answer = host.isa?(instance, class_tag: class_tag)
148
148
  question_result(answer, call_id: event.data['call_id'])
149
- when 'ExternalUnify'
150
- left_instance_id = event.data['left_instance_id']
151
- right_instance_id = event.data['right_instance_id']
152
- answer = host.unify?(left_instance_id, right_instance_id)
153
- question_result(answer, call_id: event.data['call_id'])
154
149
  when 'Debug'
155
150
  puts event.data['message'] if event.data['message']
156
151
  print 'debug> '
@@ -162,7 +157,10 @@ module Oso
162
157
  command = JSON.dump(host.to_polar(input))
163
158
  ffi_query.debug_command(command)
164
159
  when 'ExternalOp'
165
- raise UnimplementedOperationError, 'comparison operators'
160
+ op = event.data['operator']
161
+ args = event.data['args'].map(&host.method(:to_ruby))
162
+ answer = host.operator(op, args)
163
+ question_result(answer, call_id: event.data['call_id'])
166
164
  when 'NextExternal'
167
165
  call_id = event.data['call_id']
168
166
  iterable = event.data['iterable']
data/lib/oso/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Oso
4
- VERSION = '0.14.0'
4
+ VERSION = '0.14.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oso-oso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oso Security, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-16 00:00:00.000000000 Z
11
+ date: 2021-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi