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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a15e8ef705f847eafbb8235563d300ac1aa30ed6
4
- data.tar.gz: 132be2ef8d17512a3906292128c7bf624b250d55
3
+ metadata.gz: 66b2d5c63f111f3c289d29dbd3b2a7b95c259027
4
+ data.tar.gz: 03d844109d85a5e889cfbaecd343068a9bad0bff
5
5
  SHA512:
6
- metadata.gz: 0da156b1772df06f0fbc4a067f030d02b23897b452f5ba654a498661b58ef9b0d3ed35d53fada3611bdd71e14dcf985fbf21228d60c12e0cdefb4466657f09fd
7
- data.tar.gz: 4d4cb4a918feeec21f44fd3611f7990bea28599375645e89f6de0232209b102c6b5b79815ac1a9a2ca9220532a9c16cb606679c27f20f2bb99fe7c5e8e15ecc1
6
+ metadata.gz: cd0f444672b3454e4c5362f52f60a6525f415c919678dc3feb64e276126ff968e9933ff0614e8db41fd95b2cc5a277ee3ab38a15e2c2576dcaf021de5391e041
7
+ data.tar.gz: d6db065cea197a81f3fad8931652962f873b1c2e150ffc1cd69ad82b232b5c18d502ca01fc3c979bc637e4b30dd365c521f5717033a44bb2678bf629c12382fe
@@ -1,5 +1,8 @@
1
1
  require 'net/http'
2
2
  require 'jsonpath'
3
+ require 'chaoite/json_helper'
4
+
5
+ include JsonHelper
3
6
 
4
7
  module Handler
5
8
  class << self
@@ -1,31 +1,30 @@
1
1
  module JsonHelper
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)
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
- combinations = combinations.values[0].product(*combinations.values[1..-1]).map{ |x| combinations.keys.zip(x).to_h }
10
+ combinations = combinations.values[0].product(*combinations.values[1..-1]).map{ |x| combinations.keys.zip(x).to_h }
11
11
 
12
- combinations.map do |c|
13
- t = template+''
14
- c.keys.each do |key|
15
- t.gsub!(key, c[key])
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
- def valid_json?(json)
23
- begin
24
- JSON.parse(json)
25
- return true
26
- rescue Exception => e
27
- return false
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
@@ -1,3 +1,3 @@
1
1
  module Chaoite
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chaoite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aswin