json-logic-rb 0.2.0.beta1 → 0.3.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/README.md +88 -119
- data/lib/json_logic/engine.rb +6 -1
- data/lib/json_logic/errors/unknown_operator_error.rb +7 -0
- data/lib/json_logic/operations/exists.rb +1 -1
- data/lib/json_logic/operations/missing.rb +3 -1
- data/lib/json_logic/operations/missing_some.rb +1 -1
- data/lib/json_logic/operations/strict_equal.rb +13 -5
- data/lib/json_logic/operations/strict_not_equal.rb +13 -5
- data/lib/json_logic/operations/try.rb +1 -1
- data/lib/json_logic/semantics.rb +6 -0
- data/lib/json_logic/version.rb +1 -1
- data/lib/json_logic.rb +0 -1
- metadata +6 -6
- data/lib/json_logic/ext/array.rb +0 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 810c50b59976cf832b8171f84696315690a47d99a894f65e7430b6a62f5effa0
|
|
4
|
+
data.tar.gz: d398558a21b6b194da078ba175f03349ddc5f8f17a51d939e0b554f267a9e15d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a4fb7f21bfebbd7f852f62be1dc7acf4a9047aac1af3405b5d37e3c64fdc9b08b7c30b85a3168e1b64c716aefcf2526a6003b20ba5494ce2b8c55f1c5b01d225
|
|
7
|
+
data.tar.gz: 604c4a8adbe4b06fd130e0fcc07443a79899d2f1f777bf6b82da815fb9277fef5bff7c2c596329ce62042ece12d1258f0cb61fc997a43bf532546efb7881f618
|
data/README.md
CHANGED
|
@@ -1,43 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
[![jsonlogic core][src-core]][core-tests] [![jsonlogic community][src-community]][community-suites] [![compliance 100%][badge-compliance]][ci-main] [![Build Status][badge-buildkite]][ci-main] [![rubygems][badge-rubygems]][rubygems] [![license][badge-license]][license]
|
|
12
2
|
|
|
13
3
|
# json-logic-rb
|
|
14
4
|
|
|
15
|
-
Ruby implementation of [JsonLogic](https://jsonlogic.com/)
|
|
16
|
-
|
|
17
|
-
[![jsonlogic core][src-core]](https://jsonlogic.com/tests.json) [![jsonlogic community][src-community]](https://github.com/json-logic/compat-tables/tree/main/suites) [](https://github.com/tavrelkate/json-logic-rb/actions/workflows/compliance.yml?query=branch%3Amain) <a href="https://rubygems.org/gems/json-logic-rb"><img alt="rubygems" src="https://img.shields.io/gem/v/json-logic-rb"></a> <a href="LICENSE"><img alt="license" src="https://img.shields.io/badge/license-MIT-informational"></a>
|
|
5
|
+
Ruby implementation of [JsonLogic](https://jsonlogic.com/). Pure and extensible. Full compliance with both core and community-extended specifications.
|
|
18
6
|
|
|
19
7
|
## Table of Contents
|
|
20
8
|
- [What](#what)
|
|
21
9
|
- [Install](#install)
|
|
22
10
|
- [Quick start](#quick-start)
|
|
23
|
-
- [
|
|
24
|
-
|
|
25
|
-
- [2. Lazy Operations](#2-lazy-operations)
|
|
26
|
-
- [Why laziness matters?](#why-laziness-matters)
|
|
27
|
-
- [Compliance and tests](#compliance-and-tests)
|
|
28
|
-
- [Script](#script)
|
|
29
|
-
- [Supported Operations (Built‑in)](#supported-operations-built-in)
|
|
11
|
+
- [Compliance](#compliance)
|
|
12
|
+
- [Supported Operations (Built-in)](#supported-operations-built-in)
|
|
30
13
|
- [Adding Operations](#adding-operations)
|
|
31
14
|
- [Enable JsonLogic Semantics (optional)](#enable-jsonlogic-semantics-optional)
|
|
32
15
|
- [Parameters](#parameters)
|
|
33
|
-
- [Proc
|
|
16
|
+
- [Proc and Lambda](#proc-and-lambda)
|
|
34
17
|
- [Class](#class)
|
|
18
|
+
- [Laziness](#laziness)
|
|
19
|
+
- [1. Default Operations](#1-default-operations)
|
|
20
|
+
- [2. Lazy Operations](#2-lazy-operations)
|
|
21
|
+
- [Why laziness matters?](#why-laziness-matters)
|
|
35
22
|
- [JsonLogic Semantic](#jsonlogic-semantic)
|
|
36
23
|
- [Comparisons](#comparisons)
|
|
37
24
|
- [Truthiness](#truthiness)
|
|
38
25
|
- [Security](#security)
|
|
39
26
|
- [License](#license)
|
|
40
|
-
- [
|
|
27
|
+
- [Maintainers](#maintainers)
|
|
41
28
|
|
|
42
29
|
---
|
|
43
30
|
|
|
@@ -84,106 +71,22 @@ JsonLogic.apply(rule, data)
|
|
|
84
71
|
# => 42
|
|
85
72
|
```
|
|
86
73
|
|
|
87
|
-
## How
|
|
88
|
-
|
|
89
|
-
There are two types of operations: [Default Operations](#1-default-operations) and [Lazy Operations](#2-lazy-operations).
|
|
90
|
-
|
|
91
|
-
### 1. Default Operations
|
|
92
|
-
|
|
93
|
-
For **Default Operations**, the it evaluates all arguments first and then calls the operator with the resulting Ruby values.
|
|
94
|
-
This matches the reference behavior for arithmetic, comparisons, string operations, and other pure operations that do not control evaluation order.
|
|
95
|
-
|
|
96
|
-
**Groups and references:**
|
|
97
|
-
|
|
98
|
-
- [Numeric operations](https://jsonlogic.com/operations.html#numeric-operations)
|
|
99
|
-
- [String operations](https://jsonlogic.com/operations.html#string-operations)
|
|
100
|
-
- [Array operations](https://jsonlogic.com/operations.html#array-operations) — simple transform like `merge`.
|
|
101
|
-
|
|
102
|
-
### 2. Lazy Operations
|
|
103
|
-
|
|
104
|
-
Some operations must control whether and when their arguments are evaluated. They implement branching, short-circuiting, or “apply a rule per item” semantics. For these **Lazy Operations**, the engine passes raw sub-rules and data. The operator then evaluates only the sub-rules it actually needs.
|
|
105
|
-
|
|
106
|
-
**Groups and references:**
|
|
107
|
-
|
|
108
|
-
- [Logic and Boolean Operations](https://jsonlogic.com/operations.html#logic-and-boolean-operations) — short-circuit/branching like `or`.
|
|
109
|
-
- [Comparison operations](https://jsonlogic.com/operations.html#logic-and-boolean-operations) — equality/ordering like `==`.
|
|
110
|
-
- [Array operations](https://jsonlogic.com/operations.html#array-operations) — enumerable evaluation like `map`.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
**Example #1**
|
|
114
|
-
|
|
115
|
-
```ruby
|
|
116
|
-
# filter: keep numbers >= 2
|
|
117
|
-
JsonLogic.apply(
|
|
118
|
-
{ "filter" => [ { "var" => "ints" }, { ">=" => [ { "var" => "" }, 2 ] } ] },
|
|
119
|
-
{ "ints" => [1,2,3] }
|
|
120
|
-
)
|
|
121
|
-
# => [2, 3]
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### Why laziness matters?
|
|
125
74
|
|
|
126
|
-
Lazy operations prevent evaluation of branches you do not need.
|
|
127
|
-
|
|
128
|
-
If hypothetically division by zero raises an error, lazy control would avoid it.
|
|
129
|
-
```ruby
|
|
130
|
-
JsonLogic.apply({ "or" => [1, { "/" => [1, 0] }] })
|
|
131
|
-
# => 1
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
> In this gem division returns nil on divide‑by‑zero, but this example show why lazy evaluation is required by the spec: branching and boolean operators must not evaluate unused branches.
|
|
135
75
|
|
|
136
76
|
|
|
137
77
|
|
|
78
|
+
## Compliance
|
|
138
79
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
The JsonLogic specification provides test suites — concrete inputs with expected outputs that validate the implementation of operations. The specification come in two variants:
|
|
144
|
-
- [![jsonlogic core][src-core]](https://jsonlogic.com/tests.json) — [original JsonLogic website](https://jsonlogic.com/tests.json);
|
|
145
|
-
- [![jsonlogic community][src-community]](https://github.com/json-logic/compat-tables/tree/main/suites) — [extensions built on top of the core](https://github.com/json-logic/compat-tables/tree/main/suites);
|
|
80
|
+
The JsonLogic specification provides test suites — concrete inputs with expected outputs that validate the implementation of operations. The specification comes in two variants:
|
|
81
|
+
- [![jsonlogic core][src-core]](https://jsonlogic.com) – [original JsonLogic website](https://jsonlogic.com/tests.json)
|
|
82
|
+
- [![jsonlogic community][src-community]](https://github.com/json-logic) – [extensions built on top of the core](https://github.com/json-logic/compat-tables/tree/main/suites)
|
|
146
83
|
|
|
147
84
|
The "extra" exists because "core" hasn't changed in years — and that’s fine, "core" is a solid, finished foundation. Think of it as v1, while "extra" is the v2+ evolution as there are no visible plans to change the original.
|
|
148
85
|
|
|
149
|
-
### Script
|
|
150
|
-
|
|
151
|
-
Download test suite v1:
|
|
152
86
|
|
|
153
|
-
|
|
154
|
-
mkdir -p spec/tmp/v1
|
|
155
|
-
curl -L https://jsonlogic.com/tests.json -o spec/tmp/v1/tests.json
|
|
156
|
-
```
|
|
87
|
+
## Supported Operations (Built-in)
|
|
157
88
|
|
|
158
|
-
Download test suite v2:
|
|
159
89
|
|
|
160
|
-
```bash
|
|
161
|
-
mkdir -p spec/tmp/v2
|
|
162
|
-
git clone https://github.com/json-logic/compat-tables.git /tmp/compat-tables
|
|
163
|
-
ruby script/build_tests_json.rb /tmp/compat-tables/suites spec/tmp/v2/tests.json
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
Run by version:
|
|
167
|
-
|
|
168
|
-
```bash
|
|
169
|
-
ruby script/compliance.rb -v 1
|
|
170
|
-
ruby script/compliance.rb -v 2
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
Run by file path:
|
|
174
|
-
|
|
175
|
-
```bash
|
|
176
|
-
ruby script/compliance.rb -f spec/tmp/v2/tests.json
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
## Supported Operations (Built‑in)
|
|
181
|
-
|
|
182
|
-
Don’t expect JsonLogic to include every specialized operation. It’s intentionally small and not a programming language. It will never do everything.
|
|
183
|
-
|
|
184
|
-
You can add custom operations yourself — check out [§Adding Operations](https://www.google.com/search?q=%23adding-operations)— or consider if the logic can be expressed with what’s already there.
|
|
185
|
-
|
|
186
|
-
If a feature is simple, lightweight, and universally needed — open an issue or discussion.
|
|
187
90
|
|
|
188
91
|
|
|
189
92
|
| Operator | Supported | Source |
|
|
@@ -236,19 +139,32 @@ If a feature is simple, lightweight, and universally needed — open an issue or
|
|
|
236
139
|
| `throw` | ✅ |  |
|
|
237
140
|
| `preserve` | ✅ |  |
|
|
238
141
|
| Docs-only / Not implemented | | |
|
|
239
|
-
| `log` | 🚫 |  |
|
|
240
143
|
|
|
241
144
|
|
|
242
145
|
[src-core]: https://img.shields.io/badge/jsonlogic-core-2ea44f?style=flat-square
|
|
243
146
|
[src-community]: https://img.shields.io/badge/jsonlogic--community-extra-0366d6?style=flat-square
|
|
147
|
+
[badge-compliance]: https://img.shields.io/badge/compliance-100%25-brightgreen
|
|
148
|
+
[badge-buildkite]: https://img.shields.io/github/actions/workflow/status/tavrelkate/json-logic-rb/compliance.yml?branch=main&label=build
|
|
149
|
+
[badge-rubygems]: https://img.shields.io/gem/v/json-logic-rb
|
|
150
|
+
[badge-license]: https://img.shields.io/badge/license-MIT-informational
|
|
151
|
+
[core-tests]: https://jsonlogic.com
|
|
152
|
+
[community-suites]: https://github.com/json-logic
|
|
153
|
+
[ci-main]: https://github.com/tavrelkate/json-logic-rb/actions/workflows/compliance.yml?query=branch%3Amain
|
|
154
|
+
[rubygems]: https://rubygems.org/gems/json-logic-rb
|
|
155
|
+
[license]: LICENSE
|
|
156
|
+
|
|
244
157
|
|
|
245
158
|
## Adding Operations
|
|
246
159
|
|
|
247
|
-
|
|
160
|
+
Don’t expect JsonLogic to include every specialized operation. It’s intentionally small and not a programming language. It will never do everything.
|
|
161
|
+
|
|
162
|
+
Before you reach for a custom solution, see if you can express your logic using the [§Supported Operations (Built-in)](#supported-operations-built-in). Often, a simple change in perspective is all you need to get the job done with what's already there.
|
|
248
163
|
|
|
164
|
+
If that doesn't cut it, adding a custom operation is straightforward. Keep it simple: start with a Proc or a Lambda. If needed – promote it to a Class.
|
|
249
165
|
|
|
250
166
|
|
|
251
|
-
###
|
|
167
|
+
### Enable JsonLogic Semantics (optional)
|
|
252
168
|
Enable semantics to mirror JsonLogic’s comparison and truthiness in Ruby.
|
|
253
169
|
|
|
254
170
|
See [§JsonLogic Semantic](#jsonlogic-semantic) for details.
|
|
@@ -265,7 +181,7 @@ Operator function use a consistent call shape:
|
|
|
265
181
|
->((string, prefix), data) { string.to_s.start_with?(prefix.to_s) }
|
|
266
182
|
```
|
|
267
183
|
|
|
268
|
-
### Proc
|
|
184
|
+
### Proc and Lambda
|
|
269
185
|
|
|
270
186
|
Pick the Operation type.
|
|
271
187
|
|
|
@@ -286,7 +202,7 @@ JsonLogic.add_operation("starts_with", lazy: true) do |(string_rule, prefix_rule
|
|
|
286
202
|
end
|
|
287
203
|
```
|
|
288
204
|
|
|
289
|
-
See [§
|
|
205
|
+
See [§Laziness](#laziness) for details.
|
|
290
206
|
|
|
291
207
|
Use immediately:
|
|
292
208
|
|
|
@@ -329,6 +245,59 @@ JsonLogic.apply({ "starts_with" => [ { "var" => "email" }, "admin@" ] })
|
|
|
329
245
|
|
|
330
246
|
|
|
331
247
|
|
|
248
|
+
|
|
249
|
+
## Laziness
|
|
250
|
+
|
|
251
|
+
There are two types of operations: [Default Operations](#1-default-operations) and [Lazy Operations](#2-lazy-operations).
|
|
252
|
+
|
|
253
|
+
### 1. Default Operations
|
|
254
|
+
|
|
255
|
+
For **Default Operations**, the it evaluates all arguments first and then calls the operator with the resulting Ruby values.
|
|
256
|
+
This matches the reference behavior for arithmetic, comparisons, string operations, and other pure operations that do not control evaluation order.
|
|
257
|
+
|
|
258
|
+
**Groups and references:**
|
|
259
|
+
|
|
260
|
+
- [Numeric operations](https://jsonlogic.com/operations.html#numeric-operations)
|
|
261
|
+
- [String operations](https://jsonlogic.com/operations.html#string-operations)
|
|
262
|
+
- [Array operations](https://jsonlogic.com/operations.html#array-operations) — simple transform like `merge`.
|
|
263
|
+
|
|
264
|
+
### 2. Lazy Operations
|
|
265
|
+
|
|
266
|
+
Some operations must control whether and when their arguments are evaluated. They implement branching, short-circuiting, or “apply a rule per item” semantics. For these **Lazy Operations**, the engine passes raw sub-rules and data. The operator then evaluates only the sub-rules it actually needs.
|
|
267
|
+
|
|
268
|
+
**Groups and references:**
|
|
269
|
+
|
|
270
|
+
- [Logic and Boolean Operations](https://jsonlogic.com/operations.html#logic-and-boolean-operations) — short-circuit/branching like `or`.
|
|
271
|
+
- [Comparison operations](https://jsonlogic.com/operations.html#logic-and-boolean-operations) — equality/ordering like `==`.
|
|
272
|
+
- [Array operations](https://jsonlogic.com/operations.html#array-operations) — enumerable evaluation like `map`.
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
**Example #1**
|
|
276
|
+
|
|
277
|
+
```ruby
|
|
278
|
+
# filter: keep numbers >= 2
|
|
279
|
+
JsonLogic.apply(
|
|
280
|
+
{ "filter" => [ { "var" => "ints" }, { ">=" => [ { "var" => "" }, 2 ] } ] },
|
|
281
|
+
{ "ints" => [1,2,3] }
|
|
282
|
+
)
|
|
283
|
+
# => [2, 3]
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Why laziness matters?
|
|
287
|
+
|
|
288
|
+
Lazy operations prevent evaluation of branches you do not need.
|
|
289
|
+
|
|
290
|
+
If hypothetically division by zero raises an error, lazy control would avoid it.
|
|
291
|
+
```ruby
|
|
292
|
+
JsonLogic.apply({ "or" => [1, { "/" => [1, 0] }] })
|
|
293
|
+
# => 1
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
> In this gem division returns nil on divide‑by‑zero, but this example show why lazy evaluation is required by the spec: branching and boolean operators must not evaluate unused branches.
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
332
301
|
## JsonLogic Semantic
|
|
333
302
|
|
|
334
303
|
All supported Operations follow JsonLogic semantics.
|
|
@@ -391,7 +360,7 @@ using JsonLogic::Semantics
|
|
|
391
360
|
|
|
392
361
|
MIT — see [LICENSE](LICENSE).
|
|
393
362
|
|
|
394
|
-
##
|
|
363
|
+
## Maintainers
|
|
395
364
|
|
|
396
|
-
- [Valeriya Petrova](https://github.com/piatrova
|
|
365
|
+
- [Valeriya Petrova](https://github.com/valeryia-piatrova)
|
|
397
366
|
- [Tavrel Kate](https://github.com/tavrelkate)
|
data/lib/json_logic/engine.rb
CHANGED
|
@@ -33,7 +33,12 @@ module JsonLogic
|
|
|
33
33
|
return rule.transform_values { |value| evaluate(value, data) }
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
if op_class.values_only?
|
|
37
|
+
evaluated = evaluate(raw_args, data)
|
|
38
|
+
args = evaluated.is_a?(Array) ? evaluated : [evaluated]
|
|
39
|
+
else
|
|
40
|
+
args = raw_args
|
|
41
|
+
end
|
|
37
42
|
begin
|
|
38
43
|
result = op_class.new.call(args, data)
|
|
39
44
|
raise JsonLogic::NaNError.new if result.is_a?(Float) && (result.nan? || result.infinite?)
|
|
@@ -10,5 +10,5 @@ class JsonLogic::Operations::Exists < JsonLogic::Operation
|
|
|
10
10
|
|
|
11
11
|
private
|
|
12
12
|
|
|
13
|
-
def normalize_path(args, data) = args.is_a?(Array) ?
|
|
13
|
+
def normalize_path(args, data) = args.is_a?(Array) ? args.as_array.map { |part| JsonLogic.apply(part, data) } : JsonLogic.apply(args, data)
|
|
14
14
|
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
using JsonLogic::Semantics
|
|
4
|
+
|
|
3
5
|
class JsonLogic::Operations::Missing < JsonLogic::Operation
|
|
4
6
|
def self.name = "missing"
|
|
5
7
|
|
|
6
8
|
def call(args, data)
|
|
7
|
-
|
|
9
|
+
args.as_array.select { |key| JsonLogic::Tree.new(data).dig(key).nil? }
|
|
8
10
|
end
|
|
9
11
|
end
|
|
@@ -7,7 +7,7 @@ class JsonLogic::Operations::MissingSome < JsonLogic::Operation
|
|
|
7
7
|
|
|
8
8
|
def call((min_ok, list), data)
|
|
9
9
|
json = JsonLogic::Tree.new(data)
|
|
10
|
-
keys =
|
|
10
|
+
keys = list.as_array
|
|
11
11
|
missing = keys.select { |key| json.dig(key).nil? }
|
|
12
12
|
(keys.size - missing.size) >= min_ok ? [] : missing
|
|
13
13
|
end
|
|
@@ -11,14 +11,22 @@ class JsonLogic::Operations::StrictEqual < JsonLogic::LazyOperation
|
|
|
11
11
|
prev = JsonLogic.apply(args.first, data)
|
|
12
12
|
args[1..].each do |arg|
|
|
13
13
|
current = JsonLogic.apply(arg, data)
|
|
14
|
-
|
|
15
|
-
return false unless prev.to_f == current.to_f
|
|
16
|
-
else
|
|
17
|
-
return false unless prev.class == current.class && prev == current
|
|
18
|
-
end
|
|
14
|
+
return false unless strict_equal_value?(prev, current)
|
|
19
15
|
|
|
20
16
|
prev = current
|
|
21
17
|
end
|
|
22
18
|
true
|
|
23
19
|
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def strict_equal_value?(left, right)
|
|
24
|
+
if left.is_a?(Numeric) && right.is_a?(Numeric)
|
|
25
|
+
left.to_f == right.to_f
|
|
26
|
+
elsif left.is_a?(Array) || left.is_a?(Hash)
|
|
27
|
+
left.equal?(right)
|
|
28
|
+
else
|
|
29
|
+
left.class == right.class && left.eql?(right)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
24
32
|
end
|
|
@@ -11,14 +11,22 @@ class JsonLogic::Operations::StrictNotEqual < JsonLogic::LazyOperation
|
|
|
11
11
|
prev = JsonLogic.apply(args.first, data)
|
|
12
12
|
args[1..].each do |arg|
|
|
13
13
|
current = JsonLogic.apply(arg, data)
|
|
14
|
-
if
|
|
15
|
-
return false if prev.to_f == current.to_f
|
|
16
|
-
else
|
|
17
|
-
return false if prev.class == current.class && prev == current
|
|
18
|
-
end
|
|
14
|
+
return false if strict_equal_value?(prev, current)
|
|
19
15
|
|
|
20
16
|
prev = current
|
|
21
17
|
end
|
|
22
18
|
true
|
|
23
19
|
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def strict_equal_value?(left, right)
|
|
24
|
+
if left.is_a?(Numeric) && right.is_a?(Numeric)
|
|
25
|
+
left.to_f == right.to_f
|
|
26
|
+
elsif left.is_a?(Array) || left.is_a?(Hash)
|
|
27
|
+
left.equal?(right)
|
|
28
|
+
else
|
|
29
|
+
left.class == right.class && left.eql?(right)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
24
32
|
end
|
|
@@ -6,7 +6,7 @@ class JsonLogic::Operations::Try < JsonLogic::LazyOperation
|
|
|
6
6
|
def self.name = "try"
|
|
7
7
|
|
|
8
8
|
def call(arguments, data)
|
|
9
|
-
arguments =
|
|
9
|
+
arguments = arguments.as_array
|
|
10
10
|
raise JsonLogic::InvalidArgumentsError.new if arguments.empty?
|
|
11
11
|
|
|
12
12
|
state = { data: data, error: nil }
|
data/lib/json_logic/semantics.rb
CHANGED
data/lib/json_logic/version.rb
CHANGED
data/lib/json_logic.rb
CHANGED
|
@@ -6,7 +6,6 @@ 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/ext/array'
|
|
10
9
|
require_relative 'json_logic/tree'
|
|
11
10
|
require_relative 'json_logic/scope'
|
|
12
11
|
require_relative 'json_logic/operation'
|
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.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tavrel Kate
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-09-06 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/
|
|
28
|
+
- lib/json_logic/errors/unknown_operator_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
|
|
@@ -78,11 +78,11 @@ files:
|
|
|
78
78
|
- spec/tmp/v1/tests.json
|
|
79
79
|
- spec/tmp/v2/tests.json
|
|
80
80
|
- test/selftest.rb
|
|
81
|
-
homepage: https://
|
|
81
|
+
homepage: https://jsonlogic.com
|
|
82
82
|
licenses:
|
|
83
83
|
- MIT
|
|
84
84
|
metadata:
|
|
85
|
-
homepage_uri: https://
|
|
85
|
+
homepage_uri: https://jsonlogic.com
|
|
86
86
|
source_code_uri: https://github.com/tavrelkate/json-logic-rb
|
|
87
87
|
documentation_uri: https://github.com/tavrelkate/json-logic-rb
|
|
88
88
|
changelog_uri: https://github.com/tavrelkate/json-logic-rb/blob/main/CHANGELOG.md
|
|
@@ -102,5 +102,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
102
102
|
requirements: []
|
|
103
103
|
rubygems_version: 3.6.2
|
|
104
104
|
specification_version: 4
|
|
105
|
-
summary: Ruby implementation of JsonLogic
|
|
105
|
+
summary: Ruby implementation of JsonLogic. Pure and extensible. Full compliance.
|
|
106
106
|
test_files: []
|