funcml-core 0.9.0 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/funcml-core/patch/funcs/cast.rb +17 -0
- data/lib/funcml-core/patch/hash.rb +26 -1
- data/lib/funcml-core/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da9c2ae2356b8d3277cbbaecbeeed6592a285211d8cb77802cbe29aa6b60ef8b
|
4
|
+
data.tar.gz: de2322628fec13589866f907191aed5b50b7daf3c123e87d6b49ea61f4965750
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b7ee27995128146f4678e98830a55683ed3989980d78ecbb1f11584913b669cb2d010c681266b4ad3dbc5edc28dad06e42cf8ce19f832f49b07564d11c4827a
|
7
|
+
data.tar.gz: 6b57b3bb725765618c42753ae33fabb25982ec92af880720cc4721271856a570161017e4ea93393324cd7319698a5ad786c77745427beb563b81c07e987540c2
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require "json"
|
2
3
|
|
3
4
|
class Hash
|
4
5
|
def _string(mutations)
|
@@ -18,4 +19,20 @@ class Hash
|
|
18
19
|
obj.mutate(mutations).to_f
|
19
20
|
end
|
20
21
|
end
|
22
|
+
|
23
|
+
def _json(mutations)
|
24
|
+
self.fetch(:_json).then do |obj|
|
25
|
+
obj.mutate(mutations).to_json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def _fromJson(mutations)
|
30
|
+
self.fetch(:_fromJson).then do |obj|
|
31
|
+
# usage of symbolize_names instead of deep_symbolize_keys as it is only
|
32
|
+
# implemented in funcml-cli.
|
33
|
+
JSON.parse(obj, symbolize_names: true).then do |struct|
|
34
|
+
struct.mutate(mutations)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
21
38
|
end
|
@@ -7,6 +7,15 @@ class Hash
|
|
7
7
|
# dup is here to avoid iteration error on #delete/#merge
|
8
8
|
self.dup.each do |key, value|
|
9
9
|
case key
|
10
|
+
in /^\\_.*$/
|
11
|
+
# escapes keys starting with backslash (\).
|
12
|
+
# gsub is only implemented on String, not Symbol - this is why
|
13
|
+
# we cast the key to string before re-casting it to sym later.
|
14
|
+
escaped_key = key.to_s
|
15
|
+
.gsub('\\_', '_')
|
16
|
+
|
17
|
+
self[escaped_key.to_sym] = value.mutate(mutations)
|
18
|
+
self.delete(key)
|
10
19
|
in /^_.*$/
|
11
20
|
# recursive mutation of result from pattern-matched _method
|
12
21
|
# once recursively mutated, we return the final object by guard
|
@@ -53,6 +62,12 @@ class Hash
|
|
53
62
|
in {le: [first, second]}
|
54
63
|
first.mutate(mutations) <= second.mutate(mutations)
|
55
64
|
|
65
|
+
in {match: [first, second]}
|
66
|
+
first.match?(Regexp.new(second))
|
67
|
+
|
68
|
+
in {unmatch: [first, second]}
|
69
|
+
!first.match?(Regexp.new(second))
|
70
|
+
|
56
71
|
# or should evaluated by top-level if as true or false.
|
57
72
|
in {or: or_conds}
|
58
73
|
or_conds.any? do |cond|
|
@@ -154,6 +169,17 @@ class Hash
|
|
154
169
|
end
|
155
170
|
end
|
156
171
|
|
172
|
+
def _replace(mutations)
|
173
|
+
self.fetch(:_replace).then do |ctx|
|
174
|
+
content = ctx.fetch(:content)
|
175
|
+
ctx.fetch(:substitutions).each do |from, to|
|
176
|
+
content = content.gsub(from, to)
|
177
|
+
end
|
178
|
+
|
179
|
+
content
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
157
183
|
def dig_from_str(path, mutations)
|
158
184
|
path_array_sym = path.split('.').map do |sub|
|
159
185
|
sub.to_sym
|
@@ -161,5 +187,4 @@ class Hash
|
|
161
187
|
|
162
188
|
self.dig(*path_array_sym).mutate(mutations)
|
163
189
|
end
|
164
|
-
|
165
190
|
end
|
data/lib/funcml-core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: funcml-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mimopotato
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A library that implements mutations on data-structures
|
14
14
|
email:
|
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: '0'
|
64
64
|
requirements: []
|
65
|
-
rubygems_version: 3.3.
|
65
|
+
rubygems_version: 3.3.27
|
66
66
|
signing_key:
|
67
67
|
specification_version: 4
|
68
68
|
summary: funcml-core
|