jlogic_ruby 0.5.0 → 0.5.1
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 +13 -3
- data/json_logic.gemspec +4 -4
- data/lib/core_ext/deep_fetch.rb +33 -8
- data/lib/json_logic/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d80aadc506ce1aec10cdd6f89685b686071541fe7be2e001387bc845e9c1dfa7
|
|
4
|
+
data.tar.gz: ebf56729dcc0eb1547c6c694097fda35011ad1e31368fbd6f588709178ddf6bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 92a5f830c7002c5e2bc2b39464b1039bff48bf454d31c0ecf0136227088179f7629b061b376a95c8b6804c19a2cceea6801e87ac709621a14ab5725fe214d3fe
|
|
7
|
+
data.tar.gz: e8262d733e1edb8f45935e00092a06291f4ea3588a2960bb0bfd93032d143c0e0c17cf9ef13cb8c46c36d2fc3a8d3b8524e5a48d315f8e39ec7481b34de7eeb7
|
data/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# jlogic_ruby
|
|
2
|
+
|
|
3
|
+
> **This is a maintained fork** of [bhgames/json-logic-ruby](https://github.com/bhgames/json-logic-ruby), published as the [`jlogic_ruby`](https://rubygems.org/gems/jlogic_ruby) gem (the `json_logic` name is owned by the upstream project). Most of these fixes have since been merged upstream too — thanks @bhgames — this fork stays around for the couple still pending and for the `jlogic_ruby` gem name itself. Fixes: `==`/`!=` nil handling, `if`, `reduce`, `in`, `===` range matching, and a global core-class monkey-patch — see [CHANGELOG.md](CHANGELOG.md) for details. Verified against the full official [jsonlogic.com test suite](http://jsonlogic.com/tests.json) (297/297 passing).
|
|
2
4
|
|
|
3
5
|
Build complex rules, serialize them as JSON, and execute them in ruby.
|
|
4
6
|
|
|
5
|
-
**
|
|
7
|
+
**jlogic_ruby** is a ruby parser for [JsonLogic](http://jsonlogic.com). Other libraries are available for parsing this logic for Python and JavaScript at that link!
|
|
6
8
|
|
|
7
9
|
## DANGER WILL ROBINSON!
|
|
8
10
|
|
|
@@ -22,7 +24,15 @@ if you are interested.
|
|
|
22
24
|
|
|
23
25
|
## Installation
|
|
24
26
|
|
|
25
|
-
`gem install
|
|
27
|
+
`gem install jlogic_ruby`
|
|
28
|
+
|
|
29
|
+
Or in your `Gemfile`:
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
gem 'jlogic_ruby', require: 'json_logic'
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The gem name is `jlogic_ruby`, but it's a drop-in replacement — you still `require 'json_logic'` and use the `JSONLogic` module exactly as documented below.
|
|
26
36
|
|
|
27
37
|
## Why use JsonLogic?
|
|
28
38
|
|
data/json_logic.gemspec
CHANGED
|
@@ -8,15 +8,15 @@ Gem::Specification.new do |spec|
|
|
|
8
8
|
spec.version = JSONLogic::VERSION
|
|
9
9
|
spec.authors = ['Kenneth Geerts', 'Jordan Prince', 'iamzayn19']
|
|
10
10
|
spec.email = ['Kenneth.Geerts@gmail.com', 'jordanmprince@gmail.com', 'iamzayn19@gmail.com']
|
|
11
|
-
spec.homepage = 'https://github.com/iamzayn19/
|
|
11
|
+
spec.homepage = 'https://github.com/iamzayn19/jlogic_ruby'
|
|
12
12
|
spec.summary = 'Build complex rules, serialize them as JSON, and execute them in ruby'
|
|
13
13
|
spec.description = 'Build complex rules, serialize them as JSON, and execute them in ruby. Maintained fork of json_logic with fixes for nil/== handling, if, reduce, in, === range matching, and the transform_keys core monkey-patch. See http://jsonlogic.com'
|
|
14
14
|
spec.license = 'MIT'
|
|
15
15
|
|
|
16
16
|
spec.metadata = {
|
|
17
|
-
'source_code_uri' => 'https://github.com/iamzayn19/
|
|
18
|
-
'bug_tracker_uri' => 'https://github.com/iamzayn19/
|
|
19
|
-
'changelog_uri' => 'https://github.com/iamzayn19/
|
|
17
|
+
'source_code_uri' => 'https://github.com/iamzayn19/jlogic_ruby',
|
|
18
|
+
'bug_tracker_uri' => 'https://github.com/iamzayn19/jlogic_ruby/issues',
|
|
19
|
+
'changelog_uri' => 'https://github.com/iamzayn19/jlogic_ruby/blob/master/CHANGELOG.md'
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
data/lib/core_ext/deep_fetch.rb
CHANGED
|
@@ -1,17 +1,42 @@
|
|
|
1
1
|
require 'backport_dig' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.3')
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
module DeepFetchable
|
|
4
4
|
def deep_fetch(key, default = nil)
|
|
5
5
|
keys = key.to_s.split('.')
|
|
6
|
-
value =
|
|
7
|
-
value.nil? ? default : value
|
|
6
|
+
value = keys.inject(self) { |current, k| current.nil? ? nil : deep_fetch_step(current, k) }
|
|
7
|
+
value.nil? ? default : value # value can be false (Boolean)
|
|
8
|
+
rescue StandardError
|
|
9
|
+
default
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def deep_fetch_step(current, k)
|
|
15
|
+
case current
|
|
16
|
+
when Hash
|
|
17
|
+
current[k]
|
|
18
|
+
when Array
|
|
19
|
+
deep_fetch_array_step(current, k)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# A numeric key indexes the array directly. A non-numeric key against a
|
|
24
|
+
# single-element array transparently descends into that element, since a
|
|
25
|
+
# non-repeating section is still wrapped in a one-element array upstream;
|
|
26
|
+
# against an array with more (or zero) elements the key is ambiguous, so it
|
|
27
|
+
# resolves to nil rather than guessing which element was meant.
|
|
28
|
+
def deep_fetch_array_step(current, k)
|
|
29
|
+
return current[k.to_i] if k =~ /\A-?\d+\z/
|
|
30
|
+
return deep_fetch_step(current.first, k) if current.size == 1
|
|
31
|
+
|
|
32
|
+
nil
|
|
8
33
|
end
|
|
9
34
|
end
|
|
10
35
|
|
|
36
|
+
class Hash
|
|
37
|
+
include DeepFetchable
|
|
38
|
+
end
|
|
39
|
+
|
|
11
40
|
class Array
|
|
12
|
-
|
|
13
|
-
indexes = index.to_s.split('.').map(&:to_i)
|
|
14
|
-
value = dig(*indexes) rescue default
|
|
15
|
-
value.nil? ? default : value # value can be false (Boolean)
|
|
16
|
-
end
|
|
41
|
+
include DeepFetchable
|
|
17
42
|
end
|
data/lib/json_logic/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jlogic_ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kenneth Geerts
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2026-09-
|
|
13
|
+
date: 2026-09-30 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: bundler
|
|
@@ -110,13 +110,13 @@ files:
|
|
|
110
110
|
- lib/json_logic/operation.rb
|
|
111
111
|
- lib/json_logic/truthy.rb
|
|
112
112
|
- lib/json_logic/version.rb
|
|
113
|
-
homepage: https://github.com/iamzayn19/
|
|
113
|
+
homepage: https://github.com/iamzayn19/jlogic_ruby
|
|
114
114
|
licenses:
|
|
115
115
|
- MIT
|
|
116
116
|
metadata:
|
|
117
|
-
source_code_uri: https://github.com/iamzayn19/
|
|
118
|
-
bug_tracker_uri: https://github.com/iamzayn19/
|
|
119
|
-
changelog_uri: https://github.com/iamzayn19/
|
|
117
|
+
source_code_uri: https://github.com/iamzayn19/jlogic_ruby
|
|
118
|
+
bug_tracker_uri: https://github.com/iamzayn19/jlogic_ruby/issues
|
|
119
|
+
changelog_uri: https://github.com/iamzayn19/jlogic_ruby/blob/master/CHANGELOG.md
|
|
120
120
|
post_install_message:
|
|
121
121
|
rdoc_options: []
|
|
122
122
|
require_paths:
|