json-logic-rb 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 810c50b59976cf832b8171f84696315690a47d99a894f65e7430b6a62f5effa0
4
- data.tar.gz: d398558a21b6b194da078ba175f03349ddc5f8f17a51d939e0b554f267a9e15d
3
+ metadata.gz: cfab12682f9f2d3df1040be8b2b3c55d1833ed2404745ccdec697e2a41b3eca3
4
+ data.tar.gz: 941a58b2e335711d94625838071a460784116f7206233c5aab8630655c4a0bb7
5
5
  SHA512:
6
- metadata.gz: a4fb7f21bfebbd7f852f62be1dc7acf4a9047aac1af3405b5d37e3c64fdc9b08b7c30b85a3168e1b64c716aefcf2526a6003b20ba5494ce2b8c55f1c5b01d225
7
- data.tar.gz: 604c4a8adbe4b06fd130e0fcc07443a79899d2f1f777bf6b82da815fb9277fef5bff7c2c596329ce62042ece12d1258f0cb61fc997a43bf532546efb7881f618
6
+ metadata.gz: fcd3617a8beb68ba26643863c63af8782dd0db2afac949f9e370bc607c743b039c73116427f99e442d080f3ce32feef28f1f86c22b77a01aa624daf2de5923ad
7
+ data.tar.gz: aa7a45488df093289620b5f7b5e7aba2888d76784798b49ca5a0978dda8647af758a88cbe372da07bee2ce5d336347987237eabd78265d7b897342e3647e59f7
@@ -29,9 +29,7 @@ module JsonLogic
29
29
 
30
30
  name, raw_args = rule.first
31
31
  op_class = @registry.fetch(name)
32
- unless op_class
33
- return rule.transform_values { |value| evaluate(value, data) }
34
- end
32
+ raise JsonLogic::UnrecognizedOperationError.new unless op_class
35
33
 
36
34
  if op_class.values_only?
37
35
  evaluated = evaluate(raw_args, data)
@@ -19,6 +19,7 @@ module JsonLogic
19
19
  private
20
20
 
21
21
  def message_or_default(message)
22
+ # message is always a real String here today; add a nil-guard if that changes.
22
23
  self.class < JsonLogic::Error || message.empty? ? default_message : message.to_s
23
24
  end
24
25
 
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JsonLogic
4
+ class UnrecognizedOperationError < Error
5
+ DEFAULT_MESSAGE = "Unrecognized Operation"
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module JsonLogic; VERSION = '0.3.0'; end
3
+ module JsonLogic; VERSION = '0.4.0'; end
data/lib/json_logic.rb CHANGED
@@ -6,6 +6,7 @@ require_relative 'json_logic/errors/error'
6
6
  require_relative 'json_logic/errors/logic_error'
7
7
  require_relative 'json_logic/errors/invalid_arguments_error'
8
8
  require_relative 'json_logic/errors/nan_error'
9
+ require_relative 'json_logic/errors/unrecognized_operation_error'
9
10
  require_relative 'json_logic/tree'
10
11
  require_relative 'json_logic/scope'
11
12
  require_relative 'json_logic/operation'
data/test/selftest.rb CHANGED
@@ -13,3 +13,28 @@ t('and short-circuit') { JsonLogic.apply({ 'and' => [false, { '/' => [1, 0] }] }
13
13
  t('map inc') do
14
14
  JsonLogic.apply({ 'map' => [{ 'var' => 'xs' }, { "+": [{ "var": '' }, 1] }] }, { 'xs' => [1, 2, 3] }) == [2, 3, 4]
15
15
  end
16
+
17
+ t('unrecognized operation raises') do
18
+ JsonLogic.apply({ 'unknown_operation' => [1, 2] })
19
+ false
20
+ rescue JsonLogic::UnrecognizedOperationError => e
21
+ e.message == JsonLogic::UnrecognizedOperationError::DEFAULT_MESSAGE
22
+ end
23
+
24
+ t('unrecognized operation nested inside a lazy op still raises') do
25
+ JsonLogic.apply({ 'if' => [true, { 'nested_unknown_operation' => 1 }, 2] })
26
+ false
27
+ rescue JsonLogic::UnrecognizedOperationError => e
28
+ e.message == JsonLogic::UnrecognizedOperationError::DEFAULT_MESSAGE
29
+ end
30
+
31
+ t('error subclass keeps its stable type even with a custom detail message') do
32
+ JsonLogic::InvalidArgumentsError.new('some detail').message == JsonLogic::InvalidArgumentsError::DEFAULT_MESSAGE
33
+ end
34
+
35
+ t('base Error falls back to its default on a blank message (e.g. throw nil)') do
36
+ JsonLogic.apply({ 'throw' => nil })
37
+ false
38
+ rescue JsonLogic::Error => e
39
+ e.payload['type'] == JsonLogic::Error::DEFAULT_MESSAGE
40
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-logic-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tavrel Kate
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-09-06 00:00:00.000000000 Z
10
+ date: 2026-09-29 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Ruby implementation of JsonLogic. JsonLogic rules are JSON trees. The
13
13
  engine walks that tree and returns a Ruby value. Full compliance with both core
@@ -25,7 +25,7 @@ files:
25
25
  - lib/json_logic/errors/invalid_arguments_error.rb
26
26
  - lib/json_logic/errors/logic_error.rb
27
27
  - lib/json_logic/errors/nan_error.rb
28
- - lib/json_logic/errors/unknown_operator_error.rb
28
+ - lib/json_logic/errors/unrecognized_operation_error.rb
29
29
  - lib/json_logic/lazy_operation.rb
30
30
  - lib/json_logic/operation.rb
31
31
  - lib/json_logic/operations/add.rb
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JsonLogic
4
- class UnknownOperatorError < Error
5
- DEFAULT_MESSAGE = "Unknown Operator"
6
- end
7
- end