yq 0.3.0 → 0.5.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
- SHA1:
3
- metadata.gz: 13ea307e53dc5f5891524a3125352b0f3f4f147c
4
- data.tar.gz: ba5b55d4b0e2439dad0cd185c27757668d4ba10b
2
+ SHA256:
3
+ metadata.gz: b23c686b43c528364d30cf6bfa433e34287395eac5cc7eae66cb65cea5ed98eb
4
+ data.tar.gz: 495e641cfd3ee69706d3b3a00bb60cc1a68fd4a1e8caefc2218711804827856e
5
5
  SHA512:
6
- metadata.gz: 2bd15e2af64b6e19996adfae54cc82d99060d6d2cae379e73b712416f5aea746ffbf0a5939d4d155183e568511b6395238e20a24c893aa6aa85e2b1bda6d4f34
7
- data.tar.gz: a161c1fa39350c40ba7786641dcfe3bed038749a1c5fa22d7827c3e0e515ba56105795b132c4ec38b224bfa4393b5f168717c9395c68944ee5f312f7d1550541
6
+ metadata.gz: c29150cc948590da8646d41db7d7a5aabbc1ca5954af12136d538a4d1cb16c4f4006ea326ef795e4908532a0a15004c8a13108f57c67f353b90c41050b56d044
7
+ data.tar.gz: 2cba3098084dcbc90985aa3916745aa3f0de37d7f90569223e0bffd5ade82077aae56135847fea17e01e3ae5a3864bd5eab492b067f48600cfbba6b2e361c52a
@@ -0,0 +1,14 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "bundler"
4
+ directory: "/" # Location of package manifests
5
+ schedule:
6
+ interval: "daily"
7
+ commit-message:
8
+ prefix: "fix"
9
+ prefix-development: "chore"
10
+ include: "scope"
11
+ - package-ecosystem: "github-actions"
12
+ directory: "/" # Location of package manifests
13
+ schedule:
14
+ interval: "daily"
@@ -0,0 +1,54 @@
1
+ name: Rspec and Release
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ rspec:
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ os: [ubuntu-latest, macos-latest]
14
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
15
+ ruby: [2.5, 2.6, 2.7]
16
+ runs-on: ${{ matrix.os }}
17
+ steps:
18
+ - uses: actions/checkout@v2.3.4
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ bundler-cache: true
24
+ - name: Test with Rspec
25
+ run: |
26
+ bundle exec rspec --format documentation --require spec_helper
27
+ release:
28
+ if: github.event_name == 'push'
29
+ needs: rspec
30
+ runs-on: ubuntu-latest
31
+ env:
32
+ BUNDLE_DEPLOYMENT: true
33
+ steps:
34
+ - uses: actions/checkout@v2.3.4
35
+ - name: Set up Ruby 2.7
36
+ uses: ruby/setup-ruby@v1
37
+ with:
38
+ ruby-version: 2.7
39
+ bundler-cache: true
40
+ - name: Zip
41
+ run : |
42
+ zip -r yq.zip ./*
43
+ - name: Semantic Release
44
+ id: semantic
45
+ uses: cycjimmy/semantic-release-action@v2
46
+ env:
47
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48
+ GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_TOKEN }}
49
+ with:
50
+ semantic_version: 17
51
+ extra_plugins: |
52
+ @semantic-release/changelog
53
+ @semantic-release/git
54
+ semantic-release-rubygem
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # [0.5.0](https://github.com/jim80net/yq/compare/v0.4.1...v0.5.0) (2021-08-30)
2
+
3
+
4
+ ### Features
5
+
6
+ * do not install on versions of ruby that are incompatible ([63f3095](https://github.com/jim80net/yq/commit/63f30957c79393d23f3bdb3b093f48ec746dbd38))
7
+
8
+ ## [0.4.1](https://github.com/jim80net/yq/compare/v0.4.0...v0.4.1) (2021-05-01)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * release 0.4.1 ([8466cd3](https://github.com/jim80net/yq/commit/8466cd3dd2d86f1f1e0c4b29b502c58b10512add))
data/Gemfile CHANGED
@@ -1,13 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'json2yaml'
4
-
5
- group :development, :test do
6
- gem 'pry'
7
- gem 'rspec', '~> 3.3'
8
- gem 'rake'
9
- gem 'guard'
10
- gem 'guard-rspec'
11
- gem 'climate_control'
12
- gem 'coveralls', require: false
13
- end
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ yq (0.4.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ climate_control (1.0.1)
11
+ coderay (1.1.3)
12
+ diff-lcs (1.4.4)
13
+ ffi (1.15.3)
14
+ formatador (0.3.0)
15
+ guard (2.18.0)
16
+ formatador (>= 0.2.4)
17
+ listen (>= 2.7, < 4.0)
18
+ lumberjack (>= 1.0.12, < 2.0)
19
+ nenv (~> 0.1)
20
+ notiffany (~> 0.0)
21
+ pry (>= 0.13.0)
22
+ shellany (~> 0.0)
23
+ thor (>= 0.18.1)
24
+ guard-compat (1.2.1)
25
+ guard-rspec (4.7.3)
26
+ guard (~> 2.1)
27
+ guard-compat (~> 1.1)
28
+ rspec (>= 2.99.0, < 4.0)
29
+ listen (3.5.1)
30
+ rb-fsevent (~> 0.10, >= 0.10.3)
31
+ rb-inotify (~> 0.9, >= 0.9.10)
32
+ lumberjack (1.2.8)
33
+ method_source (1.0.0)
34
+ nenv (0.3.0)
35
+ notiffany (0.1.3)
36
+ nenv (~> 0.1)
37
+ shellany (~> 0.0)
38
+ parallel (1.20.1)
39
+ parser (3.0.2.0)
40
+ ast (~> 2.4.1)
41
+ pry (0.14.1)
42
+ coderay (~> 1.1)
43
+ method_source (~> 1.0)
44
+ rainbow (3.0.0)
45
+ rake (13.0.6)
46
+ rb-fsevent (0.11.0)
47
+ rb-inotify (0.10.1)
48
+ ffi (~> 1.0)
49
+ regexp_parser (2.1.1)
50
+ rexml (3.2.5)
51
+ rspec (3.10.0)
52
+ rspec-core (~> 3.10.0)
53
+ rspec-expectations (~> 3.10.0)
54
+ rspec-mocks (~> 3.10.0)
55
+ rspec-core (3.10.0)
56
+ rspec-support (~> 3.10.0)
57
+ rspec-expectations (3.10.0)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.10.0)
60
+ rspec-mocks (3.10.0)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.10.0)
63
+ rspec-support (3.10.0)
64
+ rubocop (1.20.0)
65
+ parallel (~> 1.10)
66
+ parser (>= 3.0.0.0)
67
+ rainbow (>= 2.2.2, < 4.0)
68
+ regexp_parser (>= 1.8, < 3.0)
69
+ rexml
70
+ rubocop-ast (>= 1.9.1, < 2.0)
71
+ ruby-progressbar (~> 1.7)
72
+ unicode-display_width (>= 1.4.0, < 3.0)
73
+ rubocop-ast (1.11.0)
74
+ parser (>= 3.0.1.1)
75
+ ruby-progressbar (1.11.0)
76
+ shellany (0.0.1)
77
+ thor (1.1.0)
78
+ unicode-display_width (2.0.0)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ bundler
85
+ climate_control
86
+ guard
87
+ guard-rspec
88
+ pry
89
+ rake
90
+ rspec
91
+ rubocop
92
+ yq!
93
+
94
+ BUNDLED WITH
95
+ 2.2.16
data/Guardfile CHANGED
@@ -1,9 +1,9 @@
1
- directories %w(lib bin spec )
1
+ directories %w[lib bin spec]
2
2
 
3
3
  clearing :on
4
4
 
5
- guard :rspec, cmd: "bundle exec rspec" do
6
- require "guard/rspec/dsl"
5
+ guard :rspec, cmd: 'bundle exec rspec' do
6
+ require 'guard/rspec/dsl'
7
7
  dsl = Guard::RSpec::Dsl.new(self)
8
8
 
9
9
  # Feel free to open issues for suggestions and improvements
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Yq
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/yq.svg)](http://badge.fury.io/rb/yq)
4
- [![Build Status](https://travis-ci.org/jim80net/yq.svg?branch=master)](https://travis-ci.org/jim80net/yq)
5
- [![Coverage Status](https://coveralls.io/repos/jim80net/yq/badge.svg?branch=master&service=github)](https://coveralls.io/github/jim80net/yq?branch=master)
4
+ ![Rspec and Release](https://github.com/jim80net/yq/workflows/Rspec%20and%20Release/badge.svg)
6
5
 
7
6
  Use `yq` to parse YAML documents using [jq](https://stedolan.github.io/jq/). This gem is a simple wrapper around the executable. It will convert the YAML input into JSON, run `jq` against it, then convert the output back into YAML. Sometimes, `jq` will output non-JSON, but `yq` will just turn that into valid YAML.
8
7
 
@@ -29,6 +28,8 @@ bar: baz
29
28
 
30
29
  ```
31
30
 
31
+ `yq` converts the STDIN to JSON, and passes it to `jq`, along with the `jq` query you specify. The result is then turned back into YAML.
32
+
32
33
  ## Contributing
33
34
 
34
35
  1. Fork it ( https://github.com/jim80net/yq/fork )
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
 
3
3
  Dir.glob('tasks/**/*.rake').each(&method(:import))
4
4
 
5
5
  task default: :spec
6
-
data/bin/yq CHANGED
@@ -8,17 +8,15 @@ require 'optparse'
8
8
  require 'yq'
9
9
 
10
10
  $stdout.sync = $stderr.sync = true
11
- unless defined?(LOGGER)
12
- LOGGER = Logger.new($stderr)
13
- end
11
+ LOGGER = Logger.new($stderr) unless defined?(LOGGER)
14
12
  LOGGER.level = Logger::INFO
15
13
 
16
14
  @options = {
17
- context: :main_loop
15
+ context: :main_loop,
16
+ output: :yaml
18
17
  }
19
18
 
20
-
21
- def prereqs
19
+ def prereqs
22
20
  ARGV << '--help' if ARGV.empty?
23
21
 
24
22
  opts = OptionParser.new do |opts|
@@ -28,45 +26,46 @@ def prereqs
28
26
  puts opts
29
27
  exit 0
30
28
  end
31
- opts.on('--verbose', '-v', 'verbose') do
29
+ opts.on('--verbose', '-v', 'verbose') do
32
30
  LOGGER.level = Logger::DEBUG
33
31
  end
34
- opts.on("--develop", "Run in developer mode") do
32
+ opts.on('--develop', 'Run in developer mode') do
35
33
  @options[:context] = :develop
36
34
  end
35
+ opts.on('-r', '--raw-output') do
36
+ @options[:output] = :raw
37
+ end
38
+ opts.on('--json-output') do
39
+ @options[:output] = :json
40
+ end
37
41
  end
38
42
  opts.parse!
39
-
43
+
40
44
  required_vars = %w[
41
45
  ]
42
46
  required_vars.each do |v|
43
47
  raise "#{v} must be specified in the environment variables" unless ENV[v]
44
48
  end
45
49
 
46
- raise "jq not installed" unless Yq.which('jq')
50
+ raise 'jq not installed' unless Yq.which('jq')
47
51
  end
48
52
 
49
-
50
53
  def start
51
- begin
52
- @yaml = $stdin.read
53
-
54
- puts Yq.search_yaml(ARGV[0], @yaml)
54
+ @yaml = $stdin.read
55
55
 
56
- rescue => e
57
- LOGGER.error "Unhandled exception #{e.class}: #{e.message}"
58
- e.backtrace.each do |v|
59
- LOGGER.debug v
60
- end
61
- raise
56
+ puts Yq.search_yaml(ARGV[0], @yaml, output: @options[:output])
57
+ rescue StandardError => e
58
+ LOGGER.error "Unhandled exception #{e.class}: #{e.message}"
59
+ e.backtrace.each do |v|
60
+ LOGGER.debug v
62
61
  end
63
-
62
+ raise
64
63
  end
65
64
 
66
65
  def develop
67
66
  require 'pry'
68
67
  LOGGER.level = Logger::DEBUG
69
- LOGGER.info "Develop mode"
68
+ LOGGER.info 'Develop mode'
70
69
  start
71
70
  end
72
71
 
@@ -74,6 +73,5 @@ def main_loop
74
73
  start
75
74
  end
76
75
 
77
-
78
76
  prereqs
79
- self.send(@options[:context])
77
+ send(@options[:context])
data/lib/yq/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yq
2
- VERSION = '0.3.0'
2
+ VERSION = '0.5.0'.freeze
3
3
  end
data/lib/yq.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "yq/version"
1
+ require 'yq/version'
2
2
  require 'open3'
3
3
  require 'stringio'
4
4
  require 'yaml'
@@ -8,49 +8,53 @@ require 'timeout'
8
8
  module Yq
9
9
  def self.which(cmd)
10
10
  exts = ENV['PATH'] ? ENV['PATH'].split(':') : ['']
11
- exts.each { |ext|
11
+ exts.each do |ext|
12
12
  exe = File.join(ext, cmd)
13
13
  return exe if File.executable?(exe) && !File.directory?(exe)
14
- }
15
- return nil
14
+ end
15
+ nil
16
16
  end
17
17
 
18
- def self.search_yaml(query, yaml)
18
+ def self.search_yaml(query, yaml, output: :yaml)
19
19
  req_json = yaml_to_json(yaml)
20
- resp_json = search(query, req_json)
21
- resp_yaml = json_to_yaml(resp_json)
22
- return resp_yaml
20
+ case output
21
+ when :raw
22
+ search(query, req_json, flags: ['--raw-output'])
23
+ when :json
24
+ search(query, req_json)
25
+ when :yaml
26
+ resp_json = search(query, req_json)
27
+ json_to_yaml(resp_json)
28
+ end
23
29
  end
24
30
 
25
- def self.search(query, json)
26
- cmd = which('jq') + %Q[ '#{query}']
31
+ def self.search(query, json, flags: [])
32
+ cmd = [which('jq')] + flags + [query]
27
33
  input = json
28
- output = ""
34
+ output = ''
29
35
  LOGGER.debug "sending jq #{cmd}"
30
36
 
31
- Open3.popen2(cmd) do |i, o, t|
32
- begin
33
- pid = t.pid
37
+ Open3.popen2(*cmd) do |i, o, t|
38
+ pid = t.pid
34
39
 
35
- if input
36
- i.puts input
37
- i.close
38
- end
40
+ if input
41
+ i.puts input
42
+ i.close
43
+ end
39
44
 
40
- Timeout.timeout(5) do
41
- o.each { |v|
42
- output << v
43
- }
45
+ Timeout.timeout(5) do
46
+ o.each do |v|
47
+ output << v
44
48
  end
45
- rescue Timeout::Error
46
- LOGGER.warn "Timing out #{t.inspect} after 1 second"
47
- Process.kill(15, pid)
48
- ensure
49
- status = t.value
50
- raise "JQ failed to exit cleanly" unless status.success?
51
49
  end
50
+ rescue Timeout::Error
51
+ LOGGER.warn "Timing out #{t.inspect} after 1 second"
52
+ Process.kill(15, pid)
53
+ ensure
54
+ status = t.value
55
+ raise 'JQ failed to exit cleanly' unless status.success?
52
56
  end
53
- return output
57
+ output
54
58
  end
55
59
 
56
60
  def self.yaml_to_json(yaml)
@@ -74,7 +78,7 @@ module Yq
74
78
  def self.json_to_hash(json)
75
79
  JSON.parse(json)
76
80
  rescue JSON::ParserError
77
- LOGGER.debug "Non JSON output from jq. Interpreting."
81
+ LOGGER.debug 'Non JSON output from jq. Interpreting.'
78
82
  interpret_non_json_output(json)
79
83
  end
80
84
 
@@ -88,13 +92,11 @@ module Yq
88
92
 
89
93
  without_the_wrapping_array = matches.map(&:first)
90
94
  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
95
+ JSON.parse(line)
96
+ rescue JSON::ParserError
97
+ LOGGER.debug "Assuming #{line} is a string."
98
+ obj = JSON.parse(%({ "value": #{line} }))
99
+ obj['value']
98
100
  end
99
101
  end
100
102
  end
data/release.config.js ADDED
@@ -0,0 +1,43 @@
1
+ module.exports = {
2
+ "plugins": [
3
+ "@semantic-release/commit-analyzer",
4
+ "@semantic-release/release-notes-generator",
5
+ [
6
+ "@semantic-release/changelog",
7
+ {
8
+ "changelogFile": "CHANGELOG.md"
9
+ }
10
+ ],
11
+ [
12
+ "semantic-release-rubygem",
13
+ {
14
+ "gemFileDir": "."
15
+ }
16
+ ],
17
+ [
18
+ "@semantic-release/git",
19
+ {
20
+ "assets": [
21
+ "CHANGELOG.md"
22
+ ],
23
+ "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
24
+ }
25
+ ],
26
+ [
27
+ "@semantic-release/github",
28
+ {
29
+ "assets": [
30
+ {
31
+ "path": "yq.zip",
32
+ "name": "yq.${nextRelease.version}.zip",
33
+ "label": "Full zip distribution"
34
+ },
35
+ {
36
+ "path": "yq-*.gem",
37
+ "label": "Gem distribution"
38
+ }
39
+ ]
40
+ }
41
+ ],
42
+ ]
43
+ };
data/spec/spec_helper.rb CHANGED
@@ -1,15 +1,11 @@
1
- $:.unshift(File.expand_path("../lib", File.dirname(__FILE__)))
2
-
3
- require 'coveralls'
4
- Coveralls.wear!
1
+ $:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
5
2
 
6
3
  require 'logger'
7
4
  require 'pry'
8
5
  require 'yq'
9
6
 
10
-
11
7
  LOGGER = Logger.new('/dev/null')
12
- SPEC_ROOT = File.expand_path(File.dirname(__FILE__))
8
+ SPEC_ROOT = __dir__
13
9
  WORK_ROOT = File.expand_path(File.join(SPEC_ROOT, '..'))
14
10
 
15
11
  RSpec.configure do |config|
data/spec/yq_bin_spec.rb CHANGED
@@ -4,30 +4,28 @@ require 'timeout'
4
4
 
5
5
  describe 'bin/yq' do
6
6
  # Contract Or[nil,String] => self
7
- def run_bin(args = "", input = nil)
7
+ def run_bin(args = '', input = nil)
8
8
  status = nil
9
- output = ""
9
+ output = ''
10
10
  cmd = "bin/yq #{args}"
11
11
  Open3.popen2e(cmd) do |i, oe, t|
12
- begin
13
- pid = t.pid
12
+ pid = t.pid
14
13
 
15
- if input
16
- i.puts input
17
- i.close
18
- end
14
+ if input
15
+ i.puts input
16
+ i.close
17
+ end
19
18
 
20
- Timeout.timeout(0.5) do
21
- oe.each { |v|
22
- output << v
23
- }
19
+ Timeout.timeout(1.0) do
20
+ oe.each do |v|
21
+ output << v
24
22
  end
25
- rescue Timeout::Error
26
- LOGGER.warn "Timing out #{t.inspect} after 1 second"
27
- Process.kill(15, pid)
28
- ensure
29
- status = t.value
30
23
  end
24
+ rescue Timeout::Error
25
+ LOGGER.warn "Timing out #{t.inspect} after 1 second"
26
+ Process.kill(15, pid)
27
+ ensure
28
+ status = t.value
31
29
  end
32
30
  [output, status]
33
31
  end
@@ -51,17 +49,17 @@ describe 'bin/yq' do
51
49
  end
52
50
 
53
51
  it 'supplies help' do
54
- out_err, status = run_bin("--help")
52
+ out_err, status = run_bin('--help')
55
53
  expect(out_err).to match(/Usage: yq/)
56
54
  expect(status).to be_success
57
55
  end
58
56
 
59
57
  describe 'parses' do
60
- let(:yaml) { <<-EOF }
61
- foo:
62
- bar:
63
- baz: value
64
- EOF
58
+ let(:yaml) { <<~EOF }
59
+ foo:
60
+ bar:
61
+ baz: value
62
+ EOF
65
63
 
66
64
  it '.foo.bar' do
67
65
  out_err, status = run_bin('.foo.bar', yaml)
data/spec/yq_spec.rb CHANGED
@@ -1,90 +1,99 @@
1
1
  describe Yq do
2
2
  subject { described_class }
3
3
 
4
- let(:hash) {
5
- { "foo" => { "bar" => { "baz" => "value" }}}
6
- }
7
-
8
- let(:yaml) {<<EOF}
9
- foo:
10
- bar:
11
- baz: value
12
- EOF
13
-
14
- let(:json) {<<EOF.chomp}
15
- {"foo":{"bar":{"baz":"value"}}}
16
- EOF
17
-
18
- let(:jq_response) {<<EOF}
19
- {
20
- "baz": "value"
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
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
73
- EOF
4
+ let(:hash) do
5
+ { 'foo' => { 'bar' => { "'" => 'value' } } }
6
+ end
7
+
8
+ let(:yaml) { <<~EOF }
9
+ foo:
10
+ bar:
11
+ "'": value
12
+ EOF
13
+
14
+ # support equivalent YAML syntaxes (depends on ruby version)
15
+ let(:yaml_regexp) { <<~EOF }
16
+ foo:
17
+ bar:
18
+ ("'"|''''|! ''''): value
19
+ EOF
20
+
21
+ let(:json) { <<~EOF.chomp }
22
+ {"foo":{"bar":{"'":"value"}}}
23
+ EOF
24
+
25
+ let(:jq_query) { %q({"\\t": .foo.bar["'"]}) }
26
+
27
+ let(:jq_response) { <<~EOF }
28
+ {
29
+ "\\t": "value"
30
+ }
31
+ EOF
32
+
33
+ let(:jq_non_json_response) { <<~EOF }
34
+ "foo"
35
+ "bar"
36
+ "baz"
37
+ EOF
38
+
39
+ let(:yaml_from_non_json_response) { <<~EOF }
40
+ ---
41
+ - foo
42
+ - bar
43
+ - baz
44
+ EOF
45
+
46
+ let(:jq_non_json_response_2) { <<~EOF }
47
+ {
48
+ "foo": "bar",
49
+ "baz": {
50
+ "blah": 10240,
51
+ "asdf": "qwer"
52
+ },
53
+ "bing": "bo.ng"
54
+ }
55
+ {
56
+ "foo": "far",
57
+ "bing": "ba.ng"
58
+ }
59
+ [1,2,3]
60
+ [4,5,6]
61
+ "asdf"
62
+ "qwer"
63
+ EOF
64
+
65
+ let(:yaml_from_non_json_response_2) { <<~EOF }
66
+ ---
67
+ - foo: bar
68
+ baz:
69
+ blah: 10240
70
+ asdf: qwer
71
+ bing: bo.ng
72
+ - foo: far
73
+ bing: ba.ng
74
+ - - 1
75
+ - 2
76
+ - 3
77
+ - - 4
78
+ - 5
79
+ - 6
80
+ - asdf
81
+ - qwer
82
+ EOF
74
83
 
75
84
  describe '.search' do
76
- subject { described_class.search('.foo.bar', json) }
85
+ subject { described_class.search(jq_query, json) }
77
86
 
78
87
  it { is_expected.to match(jq_response) }
79
88
 
80
89
  it 'passes it through to jq' do
81
90
  allow(Yq).to receive(:which).with('jq').and_return('/bin/jq')
82
- expect(Open3).to receive(:popen2).with(%q[/bin/jq '.foo.bar']).and_return(jq_response)
91
+ expect(Open3).to receive(:popen2).with('/bin/jq', jq_query).and_return(jq_response)
83
92
  subject
84
93
  end
85
94
 
86
95
  context 'unclean exit' do
87
- subject { described_class.search'.foobar', json }
96
+ subject { described_class.search '.foobar', json }
88
97
 
89
98
  it 'stops processing when jq exits uncleanly' do
90
99
  # not mocking at this level, see implementation
@@ -99,7 +108,7 @@ EOF
99
108
 
100
109
  describe '.hash_to_yaml' do
101
110
  subject { described_class.hash_to_yaml(hash) }
102
- it { is_expected.to match(yaml) }
111
+ it { is_expected.to match(yaml_regexp) }
103
112
  end
104
113
 
105
114
  describe '.yaml_to_json' do
@@ -109,48 +118,47 @@ EOF
109
118
 
110
119
  describe '.json_to_yaml' do
111
120
  subject { described_class.json_to_yaml(json) }
112
- it { is_expected.to match(yaml) }
121
+ it { is_expected.to match(yaml_regexp) }
113
122
 
114
123
  context 'non-json response' do
115
124
  subject { described_class.json_to_yaml(jq_non_json_response) }
116
- it {is_expected.to match(yaml_from_non_json_response)}
125
+ it { is_expected.to match(yaml_from_non_json_response) }
117
126
  end
118
127
 
119
128
  context 'non-json response 2' do
120
129
  subject { described_class.json_to_yaml(jq_non_json_response_2) }
121
- it {is_expected.to match(yaml_from_non_json_response_2)}
130
+ it { is_expected.to match(yaml_from_non_json_response_2) }
122
131
  end
123
132
  end
124
133
 
125
134
  describe '.search_yaml' do
126
135
  subject { described_class.search_yaml('.foo.bar', yaml) }
127
136
 
128
- it { is_expected.to match("baz: value") }
137
+ it { is_expected.to match(/("'"|''''|! ''''): value/) }
129
138
  end
130
139
 
131
-
132
140
  describe '.which' do
133
141
  subject { described_class.which('jq') }
134
142
 
135
- before(:each) {
136
- allow(ENV).to receive(:[]).with('PATH').and_return("/bin:/other/bin")
137
- allow(File).to receive(:executable?).with("/bin/jq").and_return(false)
138
- allow(File).to receive(:directory?).with("/bin/jq").and_return(false)
139
- allow(File).to receive(:directory?).with("/other/bin/jq").and_return(false)
140
- }
143
+ before(:each) do
144
+ allow(ENV).to receive(:[]).with('PATH').and_return('/bin:/other/bin')
145
+ allow(File).to receive(:executable?).with('/bin/jq').and_return(false)
146
+ allow(File).to receive(:directory?).with('/bin/jq').and_return(false)
147
+ allow(File).to receive(:directory?).with('/other/bin/jq').and_return(false)
148
+ end
141
149
 
142
150
  context 'but it does not exist' do
143
- before(:each) {
144
- allow(File).to receive(:executable?).with("/other/bin/jq").and_return(false)
145
- }
146
- it { is_expected.to be_falsey }
151
+ before(:each) do
152
+ allow(File).to receive(:executable?).with('/other/bin/jq').and_return(false)
153
+ end
154
+ it { is_expected.to be_falsey }
147
155
  end
148
156
 
149
157
  context 'and it does exist' do
150
- before(:each) {
151
- allow(File).to receive(:executable?).with("/other/bin/jq").and_return(true)
152
- }
153
- it { is_expected.to eq('/other/bin/jq') }
158
+ before(:each) do
159
+ allow(File).to receive(:executable?).with('/other/bin/jq').and_return(true)
160
+ end
161
+ it { is_expected.to eq('/other/bin/jq') }
154
162
  end
155
163
  end
156
164
  end
data/yq.gemspec CHANGED
@@ -1,26 +1,30 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'yq/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "yq"
6
+ spec.name = 'yq'
8
7
  spec.version = Yq::VERSION
9
- spec.authors = ["Jim Park"]
10
- spec.email = ["yq@jim80.net"]
11
- spec.summary = %q{A JQ wrapper for YAML}
8
+ spec.authors = ['Jim Park']
9
+ spec.email = ['yq@jim80.net']
10
+ spec.summary = 'A JQ wrapper for YAML'
12
11
  spec.description = "This unceremoniously shells out to a jq available in $PATH.
13
12
  Please make sure jq is installed."
14
- spec.homepage = "https://github.com/jim80net/yq"
15
- spec.license = "GPLv2"
13
+ spec.homepage = 'https://github.com/jim80net/yq'
14
+ spec.license = 'GPLv2'
16
15
 
17
16
  spec.files = `git ls-files -z`.split("\x0")
18
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
+ spec.required_ruby_version = '>=2.5', '< 3'
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.7"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec", '~> 3.3'
25
- spec.add_development_dependency "pry"
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'climate_control'
24
+ spec.add_development_dependency 'guard'
25
+ spec.add_development_dependency 'guard-rspec'
26
+ spec.add_development_dependency 'pry'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'rubocop'
26
30
  end
metadata CHANGED
@@ -1,59 +1,115 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.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: 2016-06-10 00:00:00.000000000 Z
11
+ date: 2021-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: climate_control
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
18
53
  - !ruby/object:Gem::Version
19
- version: '1.7'
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
20
76
  type: :development
21
77
  prerelease: false
22
78
  version_requirements: !ruby/object:Gem::Requirement
23
79
  requirements:
24
- - - "~>"
80
+ - - ">="
25
81
  - !ruby/object:Gem::Version
26
- version: '1.7'
82
+ version: '0'
27
83
  - !ruby/object:Gem::Dependency
28
84
  name: rake
29
85
  requirement: !ruby/object:Gem::Requirement
30
86
  requirements:
31
- - - "~>"
87
+ - - ">="
32
88
  - !ruby/object:Gem::Version
33
- version: '10.0'
89
+ version: '0'
34
90
  type: :development
35
91
  prerelease: false
36
92
  version_requirements: !ruby/object:Gem::Requirement
37
93
  requirements:
38
- - - "~>"
94
+ - - ">="
39
95
  - !ruby/object:Gem::Version
40
- version: '10.0'
96
+ version: '0'
41
97
  - !ruby/object:Gem::Dependency
42
98
  name: rspec
43
99
  requirement: !ruby/object:Gem::Requirement
44
100
  requirements:
45
- - - "~>"
101
+ - - ">="
46
102
  - !ruby/object:Gem::Version
47
- version: '3.3'
103
+ version: '0'
48
104
  type: :development
49
105
  prerelease: false
50
106
  version_requirements: !ruby/object:Gem::Requirement
51
107
  requirements:
52
- - - "~>"
108
+ - - ">="
53
109
  - !ruby/object:Gem::Version
54
- version: '3.3'
110
+ version: '0'
55
111
  - !ruby/object:Gem::Dependency
56
- name: pry
112
+ name: rubocop
57
113
  requirement: !ruby/object:Gem::Requirement
58
114
  requirements:
59
115
  - - ">="
@@ -76,9 +132,12 @@ executables:
76
132
  extensions: []
77
133
  extra_rdoc_files: []
78
134
  files:
135
+ - ".github/dependabot.yml"
136
+ - ".github/workflows/rspec_and_release.yml"
79
137
  - ".gitignore"
80
- - ".travis.yml"
138
+ - CHANGELOG.md
81
139
  - Gemfile
140
+ - Gemfile.lock
82
141
  - Guardfile
83
142
  - LICENSE
84
143
  - README.md
@@ -86,6 +145,7 @@ files:
86
145
  - bin/yq
87
146
  - lib/yq.rb
88
147
  - lib/yq/version.rb
148
+ - release.config.js
89
149
  - spec/spec_helper.rb
90
150
  - spec/yq_bin_spec.rb
91
151
  - spec/yq_spec.rb
@@ -103,15 +163,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
163
  requirements:
104
164
  - - ">="
105
165
  - !ruby/object:Gem::Version
106
- version: '0'
166
+ version: '2.5'
167
+ - - "<"
168
+ - !ruby/object:Gem::Version
169
+ version: '3'
107
170
  required_rubygems_version: !ruby/object:Gem::Requirement
108
171
  requirements:
109
172
  - - ">="
110
173
  - !ruby/object:Gem::Version
111
174
  version: '0'
112
175
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.4.8
176
+ rubygems_version: 3.1.6
115
177
  signing_key:
116
178
  specification_version: 4
117
179
  summary: A JQ wrapper for YAML
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.1.0
5
- - ruby-head
6
- # uncomment this line if your project needs to run something other than `rake`:
7
- script: bundle exec rspec --require spec_helper --color --format documentation spec