shiny_json_logic 0.3.1 → 0.3.2
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/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/shiny_json_logic/scope_stack.rb +4 -4
- data/lib/shiny_json_logic/version.rb +1 -1
- data/lib/shiny_json_logic.rb +3 -26
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 47eab10babd10e80ceeda0d5f5dc857c73a69ae7f36c5a8b09c71984e02c4243
|
|
4
|
+
data.tar.gz: 21adb41b87070e1ca2438d83fd351f3bf785ad60ce7842f889beea21d2fa7624
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10f5c5bb5bca496e4f2f0957f304658181cec45277fea2bb91f9cd6c8d4901aaa937113a433821c2e728560e84fda5149d88ac5a27b18059452d8156e55b767b
|
|
7
|
+
data.tar.gz: a4b7d20d5fbcedd32fe347d418a5efddba8adb77fb11ac6caf9dcfb06ff4e7b3585035db905ccb1242c0b1581a2a5957d83b43d76f0fec89f01524d11351e704
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
|
+
## [0.3.2] - 2026-02-28
|
|
5
|
+
### Changed
|
|
6
|
+
- Refactors scope stack as an array of arrays in order to improve performance
|
|
7
|
+
|
|
4
8
|
## [0.3.1] - 2026-02-23
|
|
5
9
|
### Changed
|
|
6
10
|
- Removes operations validation pass for optimization purposes.
|
data/Gemfile.lock
CHANGED
|
@@ -21,12 +21,12 @@ module ShinyJsonLogic
|
|
|
21
21
|
|
|
22
22
|
def initialize(root_data)
|
|
23
23
|
@root_data = root_data
|
|
24
|
-
@stack = [
|
|
24
|
+
@stack = [[@root_data, 0]]
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
# Push a new scope onto the stack (when entering an iteration)
|
|
28
28
|
def push(data, index: 0)
|
|
29
|
-
stack.push(
|
|
29
|
+
stack.push([data, index])
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
# Pop the top scope (when exiting an iteration)
|
|
@@ -36,7 +36,7 @@ module ShinyJsonLogic
|
|
|
36
36
|
|
|
37
37
|
# Returns the current scope's data (top of stack)
|
|
38
38
|
def current
|
|
39
|
-
stack.last[
|
|
39
|
+
stack.last[0]
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
# Resolve a value by going up n levels and then accessing keys
|
|
@@ -51,7 +51,7 @@ module ShinyJsonLogic
|
|
|
51
51
|
scope = stack[target_index]
|
|
52
52
|
return nil unless scope
|
|
53
53
|
|
|
54
|
-
data = scope[
|
|
54
|
+
data = scope[0]
|
|
55
55
|
|
|
56
56
|
if keys.empty?
|
|
57
57
|
data
|
data/lib/shiny_json_logic.rb
CHANGED
|
@@ -16,10 +16,12 @@ module ShinyJsonLogic
|
|
|
16
16
|
Engine.call(rule, scope_stack)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
# Recursively converts all hash keys to strings
|
|
19
|
+
# Recursively converts all hash keys to strings.
|
|
20
|
+
# Fast path: if all keys are already strings, skip the copy.
|
|
20
21
|
def self.deep_stringify_keys(obj)
|
|
21
22
|
case obj
|
|
22
23
|
when Hash
|
|
24
|
+
return obj if obj.keys.all? { |k| k.is_a?(String) }
|
|
23
25
|
obj.each_with_object({}) do |(key, value), result|
|
|
24
26
|
result[key.to_s] = deep_stringify_keys(value)
|
|
25
27
|
end
|
|
@@ -29,31 +31,6 @@ module ShinyJsonLogic
|
|
|
29
31
|
obj
|
|
30
32
|
end
|
|
31
33
|
end
|
|
32
|
-
|
|
33
|
-
# Validates that all operations in the rule tree use known operators
|
|
34
|
-
def self.validate_operators!(rule)
|
|
35
|
-
case rule
|
|
36
|
-
when Hash
|
|
37
|
-
return if rule.empty?
|
|
38
|
-
|
|
39
|
-
# Multi-key hashes are invalid
|
|
40
|
-
if rule.size > 1
|
|
41
|
-
raise Errors::UnknownOperator
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
operation, args = rule.first
|
|
45
|
-
|
|
46
|
-
# Check if operation is known
|
|
47
|
-
unless OperatorSolver::SOLVERS.key?(operation.to_s)
|
|
48
|
-
raise Errors::UnknownOperator
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# Recursively validate args
|
|
52
|
-
validate_operators!(args)
|
|
53
|
-
when Array
|
|
54
|
-
rule.each { |item| validate_operators!(item) }
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
34
|
end
|
|
58
35
|
|
|
59
36
|
JsonLogic = ShinyJsonLogic
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shiny_json_logic
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Luis Moyano
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-02-
|
|
11
|
+
date: 2026-02-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|