chaoite 0.1.4 → 0.1.5
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/chaoite/handler.rb +3 -0
- data/lib/chaoite/json_helper.rb +21 -22
- data/lib/chaoite/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66b2d5c63f111f3c289d29dbd3b2a7b95c259027
|
4
|
+
data.tar.gz: 03d844109d85a5e889cfbaecd343068a9bad0bff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd0f444672b3454e4c5362f52f60a6525f415c919678dc3feb64e276126ff968e9933ff0614e8db41fd95b2cc5a277ee3ab38a15e2c2576dcaf021de5391e041
|
7
|
+
data.tar.gz: d6db065cea197a81f3fad8931652962f873b1c2e150ffc1cd69ad82b232b5c18d502ca01fc3c979bc637e4b30dd365c521f5717033a44bb2678bf629c12382fe
|
data/lib/chaoite/handler.rb
CHANGED
data/lib/chaoite/json_helper.rb
CHANGED
@@ -1,31 +1,30 @@
|
|
1
1
|
module JsonHelper
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
def resolve_json_path(json, template)
|
3
|
+
if template.start_with?("$") then
|
4
|
+
JsonPath.on(json, template)
|
5
|
+
else
|
6
|
+
paths = template.scan(/(\{(.*?)\})/).uniq
|
7
|
+
return template if paths.empty?
|
8
|
+
combinations = paths.map { |path| {path[0] => JsonPath.on(json, path[1])} }.reduce(&:merge)
|
9
9
|
|
10
|
-
|
10
|
+
combinations = combinations.values[0].product(*combinations.values[1..-1]).map{ |x| combinations.keys.zip(x).to_h }
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
t
|
12
|
+
combinations.map do |c|
|
13
|
+
t = template+''
|
14
|
+
c.keys.each do |key|
|
15
|
+
t.gsub!(key, c[key])
|
18
16
|
end
|
17
|
+
t
|
19
18
|
end
|
20
19
|
end
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
22
|
+
def valid_json?(json)
|
23
|
+
begin
|
24
|
+
JSON.parse(json)
|
25
|
+
return true
|
26
|
+
rescue Exception => e
|
27
|
+
return false
|
29
28
|
end
|
30
|
-
|
29
|
+
end
|
31
30
|
end
|
data/lib/chaoite/version.rb
CHANGED