yq 0.0.3 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ff4345f8c77a644d5a97600d15eb5f7ae59f49f
4
- data.tar.gz: cac6d3daacb77f74e0b09a8ab3931a8f7498e6cf
3
+ metadata.gz: 19dc75e5f483ae1a839dd25c5709ac1e2ace615c
4
+ data.tar.gz: de6afd26f5e16c93db90e12835c808e7ee2c466e
5
5
  SHA512:
6
- metadata.gz: 7b91f9ad0bf43aae28d98fca8b8d3a4c3dae4f095c997c4815d04b38e6e275a4872b1030077870bc037bb5f73c850e7cbe2c63feca0a08ad779aeca514a39a79
7
- data.tar.gz: ca2b430365ff2b01d3d85f60d4432382273d43ccc2699abfb7a43fd9f22c7d4a3c589fbb5a457e945e846f3bf323b2fbe8f018cc41daed44941ce778f2b86515
6
+ metadata.gz: e4cede22d2c30f2aa9abe105270da7cb271929fd54d63e6b470b0345d927d345b205c8d640a656585c1e622734045b134029c84b56c8747d2ec3f26fc4b52aaa
7
+ data.tar.gz: b4f4c255edf8118bd025610295127870dd129b713aa3d3fa3fdae1f746a4848a7e29fbda5a93d8896587ea59507847826d233d35d113862be2ea3a270800e20b
data/Gemfile CHANGED
@@ -1,7 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'contracts'
4
-
5
3
  group :development, :test do
6
4
  gem 'pry'
7
5
  gem 'rspec', '~> 3.3'
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Yq
2
2
 
3
- Use `yq` to parse YAML documents using [JMESPath](http://jmespath.org/). This gem is a simple wrapper around the [jmespath gem](https://github.com/jmespath/jmespath.rb).
3
+ Use `yq` to parse YAML documents using [jq](https://stedolan.github.io/jq/). This gem is a simple wrapper around the executable. `jq` should be available in your path to use this gem.
4
4
 
5
5
  ## Installation
6
6
 
@@ -29,7 +29,7 @@ stuff:
29
29
  foo:
30
30
  bar: baz
31
31
 
32
- $ cat stuff.yml | yq 'stuff.foo'
32
+ $ cat stuff.yml | yq '.stuff.foo'
33
33
  ---
34
34
  bar: baz
35
35
 
@@ -37,7 +37,7 @@ bar: baz
37
37
 
38
38
  ## Contributing
39
39
 
40
- 1. Fork it ( https://github.com/[my-github-username]/yq/fork )
40
+ 1. Fork it ( https://github.com/jim80net/yq/fork )
41
41
  2. Create your feature branch (`git checkout -b my-new-feature`)
42
42
  3. Commit your changes (`git commit -am 'Add some feature'`)
43
43
  4. Push to the branch (`git push origin my-new-feature`)
data/lib/yq.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require "yq/version"
2
2
  require 'open3'
3
- require 'contracts'
4
3
  require 'stringio'
5
4
  require 'yaml'
6
5
  require 'json'
@@ -74,9 +73,19 @@ module Yq
74
73
 
75
74
  def self.json_to_hash(json)
76
75
  JSON.parse(json)
76
+ rescue JSON::ParserError => e
77
+ LOGGER.debug "Non JSON output from jq. Interpreting."
78
+ interpret_non_json_output(json)
77
79
  end
78
80
 
79
81
  def self.hash_to_json(hash)
80
82
  hash.to_json
81
83
  end
84
+
85
+ def self.interpret_non_json_output(string)
86
+ string.split("\n").map do |line|
87
+ obj = JSON.parse(%Q[{ "value": #{line} }])
88
+ obj["value"]
89
+ end
90
+ end
82
91
  end
@@ -1,3 +1,3 @@
1
1
  module Yq
2
- VERSION = '0.0.3'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -19,6 +19,19 @@ EOF
19
19
  {
20
20
  "baz": "value"
21
21
  }
22
+ EOF
23
+
24
+ let(:jq_non_json_response) {<<EOF}
25
+ "foo"
26
+ "bar"
27
+ "baz"
28
+ EOF
29
+
30
+ let(:yaml_from_non_json_response) {<<EOF}
31
+ ---
32
+ - foo
33
+ - bar
34
+ - baz
22
35
  EOF
23
36
 
24
37
  describe '.search' do
@@ -28,14 +41,16 @@ EOF
28
41
 
29
42
  it 'passes it through to jq' do
30
43
  allow(Yq).to receive(:which).with('jq').and_return('/bin/jq')
31
- expect(Open3).to receive(:popen2).with('/bin/jq .foo.bar').and_return(jq_response)
44
+ expect(Open3).to receive(:popen2).with(%q[/bin/jq '.foo.bar']).and_return(jq_response)
32
45
  subject
33
46
  end
34
47
 
35
- subject { described_class.search'.foobar', json }
48
+ context 'unclean exit' do
49
+ subject { described_class.search'.foobar', json }
36
50
 
37
- it 'stops processing when jq exits uncleanly' do
38
- # not mocking at this level, see implementation
51
+ it 'stops processing when jq exits uncleanly' do
52
+ # not mocking at this level, see implementation
53
+ end
39
54
  end
40
55
  end
41
56
 
@@ -57,6 +72,11 @@ EOF
57
72
  describe '.json_to_yaml' do
58
73
  subject { described_class.json_to_yaml(json) }
59
74
  it { is_expected.to match(yaml) }
75
+
76
+ context 'non-json response' do
77
+ subject { described_class.json_to_yaml(jq_non_json_response) }
78
+ it {is_expected.to match(yaml_from_non_json_response)}
79
+ end
60
80
  end
61
81
 
62
82
  describe '.search_yaml' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Park
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-07 00:00:00.000000000 Z
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler