yq 0.1.1 → 0.2.0
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/yq.rb +13 -4
- data/lib/yq/version.rb +1 -1
- data/spec/yq_spec.rb +43 -0
- 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: e0df4607bd133443c36744c12e135d7f57ec02f2
|
4
|
+
data.tar.gz: 3141a098d8867570ccb20dc1c401763a52a63e11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ad934af4fbcf11be95bd2b39b122381811307c16c4345701c75d889d8e22fe59c5589e5667a127f51dd8de85eeaa9c10831ad80d0eb3bf8ad84f4912e29d1c9
|
7
|
+
data.tar.gz: d9e4567ac0c06ca1e9b396563bcc8ac054f7dc237f84246aef625e210797f2a7e48d90db9a74d30224038088b481f37f0c303c94c7f8d51299db98a48bda487e
|
data/lib/yq.rb
CHANGED
@@ -73,7 +73,7 @@ module Yq
|
|
73
73
|
|
74
74
|
def self.json_to_hash(json)
|
75
75
|
JSON.parse(json)
|
76
|
-
rescue JSON::ParserError
|
76
|
+
rescue JSON::ParserError
|
77
77
|
LOGGER.debug "Non JSON output from jq. Interpreting."
|
78
78
|
interpret_non_json_output(json)
|
79
79
|
end
|
@@ -83,9 +83,18 @@ module Yq
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def self.interpret_non_json_output(string)
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
regex = /(^\{.+?^\}|^\[.+?\]|^".+?")/m
|
87
|
+
matches = string.scan(regex)
|
88
|
+
|
89
|
+
without_the_wrapping_array = matches.map(&:first)
|
90
|
+
without_the_wrapping_array.map do |line|
|
91
|
+
begin
|
92
|
+
JSON.parse(line)
|
93
|
+
rescue JSON::ParserError
|
94
|
+
LOGGER.debug "Assuming #{line} is a string."
|
95
|
+
obj = JSON.parse(%Q[{ "value": #{line} }])
|
96
|
+
obj["value"]
|
97
|
+
end
|
89
98
|
end
|
90
99
|
end
|
91
100
|
end
|
data/lib/yq/version.rb
CHANGED
data/spec/yq_spec.rb
CHANGED
@@ -32,6 +32,44 @@ EOF
|
|
32
32
|
- foo
|
33
33
|
- bar
|
34
34
|
- baz
|
35
|
+
EOF
|
36
|
+
|
37
|
+
let(:jq_non_json_response_2) {<<EOF}
|
38
|
+
{
|
39
|
+
"foo": "bar",
|
40
|
+
"baz": {
|
41
|
+
"blah": 10240,
|
42
|
+
"asdf": "qwer"
|
43
|
+
},
|
44
|
+
"bing": "bo.ng"
|
45
|
+
}
|
46
|
+
{
|
47
|
+
"foo": "far",
|
48
|
+
"bing": "ba.ng"
|
49
|
+
}
|
50
|
+
[1,2,3]
|
51
|
+
[4,5,6]
|
52
|
+
"asdf"
|
53
|
+
"qwer"
|
54
|
+
EOF
|
55
|
+
|
56
|
+
let(:yaml_from_non_json_response_2) {<<EOF}
|
57
|
+
---
|
58
|
+
- foo: bar
|
59
|
+
baz:
|
60
|
+
blah: 10240
|
61
|
+
asdf: qwer
|
62
|
+
bing: bo.ng
|
63
|
+
- foo: far
|
64
|
+
bing: ba.ng
|
65
|
+
- - 1
|
66
|
+
- 2
|
67
|
+
- 3
|
68
|
+
- - 4
|
69
|
+
- 5
|
70
|
+
- 6
|
71
|
+
- asdf
|
72
|
+
- qwer
|
35
73
|
EOF
|
36
74
|
|
37
75
|
describe '.search' do
|
@@ -77,6 +115,11 @@ EOF
|
|
77
115
|
subject { described_class.json_to_yaml(jq_non_json_response) }
|
78
116
|
it {is_expected.to match(yaml_from_non_json_response)}
|
79
117
|
end
|
118
|
+
|
119
|
+
context 'non-json response 2' do
|
120
|
+
subject { described_class.json_to_yaml(jq_non_json_response_2) }
|
121
|
+
it {is_expected.to match(yaml_from_non_json_response_2)}
|
122
|
+
end
|
80
123
|
end
|
81
124
|
|
82
125
|
describe '.search_yaml' do
|