json-logic-rb 0.3.1 → 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 +4 -4
- data/lib/json_logic/engine.rb +1 -3
- data/lib/json_logic/errors/error.rb +1 -0
- data/lib/json_logic/errors/unrecognized_operation_error.rb +7 -0
- data/lib/json_logic/version.rb +1 -1
- data/lib/json_logic.rb +1 -0
- data/test/selftest.rb +25 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cfab12682f9f2d3df1040be8b2b3c55d1833ed2404745ccdec697e2a41b3eca3
|
|
4
|
+
data.tar.gz: 941a58b2e335711d94625838071a460784116f7206233c5aab8630655c4a0bb7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fcd3617a8beb68ba26643863c63af8782dd0db2afac949f9e370bc607c743b039c73116427f99e442d080f3ce32feef28f1f86c22b77a01aa624daf2de5923ad
|
|
7
|
+
data.tar.gz: aa7a45488df093289620b5f7b5e7aba2888d76784798b49ca5a0978dda8647af758a88cbe372da07bee2ce5d336347987237eabd78265d7b897342e3647e59f7
|
data/lib/json_logic/engine.rb
CHANGED
|
@@ -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)
|
data/lib/json_logic/version.rb
CHANGED
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.
|
|
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-
|
|
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,6 +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/unrecognized_operation_error.rb
|
|
28
29
|
- lib/json_logic/lazy_operation.rb
|
|
29
30
|
- lib/json_logic/operation.rb
|
|
30
31
|
- lib/json_logic/operations/add.rb
|