qig 0.1.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 292d057f6d955c48f359653bfacee7ccdc90185efa7bfa36dc206174e851d4ce
4
- data.tar.gz: 6da1eed1a718565ebb32e24db46653f14db85a0e9481a6c85e18098bc24dde70
3
+ metadata.gz: f92505d2904e0032d3fcd5b33f03540a7ce8d09080bc50a534ede7e2daecf686
4
+ data.tar.gz: 16caa89894a03819be080591bd729b89ddfb743712122fff401b18e2e2ba0ae9
5
5
  SHA512:
6
- metadata.gz: 92e236a404eec68a4a58d02a76b054e2c269519339e01f5762602a247d20dfaf9e115dea42e05823be9d48a36cad2cd35dc36dce7bc68743dd86f83b09ce9e0a
7
- data.tar.gz: 4bef37ce773fb8b8872a645dbe1f2ab7dbc90671e994bb7b12c8b5f4484072b6a0168438a801975d24f8a59d934398328b3062cb2f13f59359e26fb4c342acfc
6
+ metadata.gz: ab2d2ace58c87bc6117a20d9ca2e6b1d329398cd5ce895fb2f206abb5f66a06782b4f8d3d48716719e2a67f7091f6e938aebc9bc7e329652782583952b82533a
7
+ data.tar.gz: 9362297e8f6feb6a9f390302ae7d12093877fdd3215f5894b366a05b41330093479b027745b6579ff546bba4f27a79f539d5f985ed89c1a87c07d663acdbe9c7
data/.rubocop.yml CHANGED
@@ -1,5 +1,12 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
3
4
 
4
5
  Layout/LineLength:
5
6
  Max: 120
7
+
8
+ Metrics/BlockLength:
9
+ IgnoredMethods: ['describe', 'context']
10
+
11
+ Style/DocumentationMethod:
12
+ Enabled: true
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/CHANGELOG.md CHANGED
@@ -1,3 +1,48 @@
1
+ # 0.3.0 (January 24, 2022)
2
+
3
+ ## BREAKING CHANGES
4
+
5
+ - drop ruby 2.6 support, because Ruby 2.6 will be EOL in 2 months, and Ruby 2.7 pattern matching syntax makes
6
+ command parsing cases *much* easier to maintain, keeping the main switching logic a single-level `case`
7
+
8
+ ## Features
9
+
10
+ - method invocation syntax (e.g. for filtering)
11
+ - quoting syntax to use operators as literal keys
12
+ - reboxing operator or value collection operator, inverse of the value iteration operator
13
+
14
+ ## Documentation
15
+
16
+ - Reorganize and explain literate specs
17
+ - Specs for dig conformance
18
+
19
+ ## Fixes
20
+
21
+ - On invalid access to struct, return nil, for better conformance to Struct#dig. Previously this raised error.
22
+
23
+ # 0.2.0 (January 14, 2022)
24
+
25
+ ## Features
26
+
27
+ - Value iteration(`[]` over hashes)
28
+
29
+ ## Documentation
30
+
31
+ - Initial yard documentation on method and module
32
+ - Document and spec that we can qig into Structs and OpenStructs
33
+
34
+ # 0.1.3 (January 13, 2022)
35
+
36
+ ## Documentation
37
+
38
+ - fix changelog uri (again)
39
+
40
+ # 0.1.2 (January 13, 2022)
41
+
42
+ ## Documentation
43
+
44
+ - fix changelog uri
45
+
1
46
  # 0.1.1 (January 13, 2022)
2
47
 
3
48
  ## Documentation
@@ -10,4 +55,4 @@
10
55
  ## Features
11
56
 
12
57
  - Ability to qig into arrays and hashes
13
- - Value iteration (`[]`) over arrays
58
+ - Value iteration (`[]`) over arrays
data/Gemfile CHANGED
@@ -5,10 +5,11 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in qig.gemspec
6
6
  gemspec
7
7
 
8
+ gem 'pry', '~> 0.14.1'
8
9
  gem 'rake', '~> 13.0'
9
-
10
10
  gem 'rspec', '~> 3.0'
11
-
11
+ gem 'rspec_junit_formatter', '~> 0.5.1'
12
12
  gem 'rubocop', '~> 1.21'
13
-
14
- gem "pry", "~> 0.14.1"
13
+ gem 'rubocop-rake', '~> 0.6.0'
14
+ gem 'rubocop-rspec', '~> 2.7'
15
+ gem 'yard', '~> 0.9.27'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qig (0.1.1)
4
+ qig (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -33,6 +33,8 @@ GEM
33
33
  diff-lcs (>= 1.2.0, < 2.0)
34
34
  rspec-support (~> 3.10.0)
35
35
  rspec-support (3.10.3)
36
+ rspec_junit_formatter (0.5.1)
37
+ rspec-core (>= 2, < 4, != 2.12.0)
36
38
  rubocop (1.24.1)
37
39
  parallel (~> 1.10)
38
40
  parser (>= 3.0.0.0)
@@ -44,8 +46,15 @@ GEM
44
46
  unicode-display_width (>= 1.4.0, < 3.0)
45
47
  rubocop-ast (1.15.1)
46
48
  parser (>= 3.0.1.1)
49
+ rubocop-rake (0.6.0)
50
+ rubocop (~> 1.0)
51
+ rubocop-rspec (2.7.0)
52
+ rubocop (~> 1.19)
47
53
  ruby-progressbar (1.11.0)
48
54
  unicode-display_width (2.1.0)
55
+ webrick (1.7.0)
56
+ yard (0.9.27)
57
+ webrick (~> 1.7.0)
49
58
 
50
59
  PLATFORMS
51
60
  x86_64-linux
@@ -55,7 +64,11 @@ DEPENDENCIES
55
64
  qig!
56
65
  rake (~> 13.0)
57
66
  rspec (~> 3.0)
67
+ rspec_junit_formatter (~> 0.5.1)
58
68
  rubocop (~> 1.21)
69
+ rubocop-rake (~> 0.6.0)
70
+ rubocop-rspec (~> 2.7)
71
+ yard (~> 0.9.27)
59
72
 
60
73
  BUNDLED WITH
61
74
  2.3.4
data/README.md CHANGED
@@ -1,16 +1,23 @@
1
1
  # Qig
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/qig.svg)](https://badge.fury.io/rb/qig)
4
+ [![CircleCI](https://circleci.com/gh/NAR8789/qig-ruby/tree/main.svg?style=shield)](https://circleci.com/gh/NAR8789/qig-ruby/tree/main)
5
+
3
6
  qig is dig extended with jq's "value iterator" `[]` operator.
4
7
 
5
8
  ## Features
6
9
 
7
- - [x] qig into arrays and hashes
8
- - [ ] qig into structs
9
- - [ ] qig into OpenStructs
10
- - [ ] qig into CSV::Tables
11
- - [ ] qig into CSV::Rows
12
- - [x] value iteration over arrays
13
- - [ ] value iteration over hashes
10
+ - [x] compatible with dig
11
+ - [x] qig into arrays and hashes
12
+ - [x] qig into structs
13
+ - [x] qig into OpenStructs
14
+ - [x] qig into CSV::Tables
15
+ - [x] qig into CSV::Rows
16
+ - [x] nifty jq extensions
17
+ - [x] value iteration over arrays
18
+ - [x] value iteration over hashes
19
+ - [x] invoke ruby methods during inside the filter chain
20
+ - [x] value collect: `[[]]`, inverse of the `[]` operator. Collect streamed values back into an array
14
21
  - [ ] option to monkey patch this for more dig-like `subject.qig(*path)` syntax
15
22
 
16
23
  ## Installation
data/bin/console CHANGED
@@ -7,5 +7,5 @@ require 'qig'
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
9
9
 
10
- require "pry"
10
+ require 'pry'
11
11
  Pry.start
data/lib/qig/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Qig
4
- VERSION = '0.1.1'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/qig.rb CHANGED
@@ -2,39 +2,88 @@
2
2
 
3
3
  require_relative 'qig/version'
4
4
 
5
+ # Combining the powers of `dig` and `jq`.
6
+ # Qig is dig extended with jq's value iteration `[]` operator.
5
7
  module Qig
6
- def self.qig(*args)
7
- unit_qig(*args)
8
- end
8
+ class << self
9
+ # @param subject [Array, Hash, #[]] `subject` to be qug into.
10
+ # @param path [Array<String, Symbol, Array, Object>] retrieval path to apply to `subject`
11
+ #
12
+ # @return [Object, Array<Object>] the value(s) of `subject` located at `path`
13
+ def qig(subject, *path)
14
+ unit_qig(subject, *path)
15
+ end
16
+
17
+ # "values" as in jq's "value iterator".
18
+ #
19
+ # Coerce to array by taking the .values. Intuitively, get all possible values of `arrayish[x]`.
20
+ #
21
+ # @param arrayish [Array, Hash, #values, Object] array or hash or other to coerce to values
22
+ # @return [Array, Array, Array, Object] array of coerced values
23
+ def values(arrayish)
24
+ arrayish.respond_to?(:values) ? arrayish.values : arrayish
25
+ end
9
26
 
10
- def self.unit_qig(subject, *path)
11
- return subject if subject.nil?
27
+ private
12
28
 
13
- head, *rest = path
14
- case head
15
- when nil
16
- subject
17
- when []
18
- collection_qig(subject, *rest)
19
- # hmm... what should happen if I [] on something not an array?
20
- else
21
- unit_qig(subject[head], *rest)
29
+ def unit_qig(subject, *path) # rubocop:disable Metrics/MethodLength
30
+ head, *rest = path
31
+ case head
32
+ in nil
33
+ subject
34
+ in []
35
+ collection_qig(values(subject), *rest)
36
+ in [[]]
37
+ unit_qig([subject], *rest)
38
+ in ['', key]
39
+ unit_qig(step(subject, key), *rest)
40
+ in [[method, [*args], block]]
41
+ unit_qig(subject.public_send(method, *args, &block), *rest)
42
+ in [[method, [*args]]]
43
+ unit_qig(subject.public_send(method, *args), *rest)
44
+ in [[method]]
45
+ unit_qig(subject.public_send(method), *rest)
46
+ in [method, *]
47
+ raise ArgumentError, 'stream method invocation not applicable in unit context'
48
+ else
49
+ unit_qig(step(subject, head), *rest)
50
+ end
22
51
  end
23
- end
24
52
 
25
- def self.collection_qig(subjects, *path)
26
- return subjects if subjects.empty?
53
+ def collection_qig(subjects, *path) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
54
+ head, *rest = path
55
+ case head
56
+ in nil
57
+ subjects
58
+ in []
59
+ collection_qig(subjects.map(&method(:values)).flatten(1), *rest)
60
+ in [[]]
61
+ unit_qig(subjects, *rest)
62
+ in ['', key]
63
+ collection_qig(subjects.map { |s| step(s, key) }, *rest)
64
+ in [[method, [*args], block]]
65
+ collection_qig(subjects.map { |s| s.public_send(method, *args, &block) }, *rest)
66
+ in [[method, [*args]]]
67
+ collection_qig(subjects.map { |s| s.public_send(method, *args) }, *rest)
68
+ in [[method]]
69
+ collection_qig(subjects.map { |s| s.public_send(method) }, *rest)
70
+ in [method, [*args], block]
71
+ collection_qig(subjects.public_send(method, *args, &block), *rest)
72
+ in [method, [*args]]
73
+ collection_qig(subjects.public_send(method, *args), *rest)
74
+ in [method]
75
+ collection_qig(subjects.public_send(method), *rest)
76
+ else
77
+ collection_qig(subjects.map { |s| step(s, head) }, *rest)
78
+ end
79
+ end
27
80
 
28
- head, *rest = path
29
- case head
30
- when nil
31
- subjects
32
- when []
33
- collection_qig(subjects.flatten(1), *rest)
34
- # not sure this is quite jq-compliant... [] refuses to iterate over atoms, but flatten will just preserve them.
35
- # maybe more in the spirit of `dig` though?
36
- else
37
- collection_qig(subjects.map { |e| e.nil? ? e : e[head] }, *rest)
81
+ def step(subject, key)
82
+ subject&.[](key)
83
+ rescue NameError, IndexError
84
+ # Struct's [] is strict and raises on missing key.
85
+ # TODO: more efficient / prettier way of doing this. How does struct itself implement dig?
86
+ nil
38
87
  end
39
88
  end
40
89
  end
data/qig.gemspec CHANGED
@@ -12,11 +12,11 @@ Gem::Specification.new do |spec|
12
12
  # spec.description = "TODO: Write a longer description or delete this line."
13
13
  spec.homepage = 'https://github.com/NAR8789/qig-ruby'
14
14
  spec.license = 'MIT'
15
- spec.required_ruby_version = '>= 2.6.0'
15
+ spec.required_ruby_version = '>= 2.7.0'
16
16
 
17
17
  spec.metadata['homepage_uri'] = spec.homepage
18
18
  spec.metadata['source_code_uri'] = spec.homepage
19
- spec.metadata['changelog_uri'] = "#{spec.homepage}/CHANGELOG.txt"
19
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -34,4 +34,5 @@ Gem::Specification.new do |spec|
34
34
 
35
35
  # For more information and examples about making a new gem, check out our
36
36
  # guide at: https://bundler.io/guides/creating_gem.html
37
+ spec.metadata['rubygems_mfa_required'] = 'true'
37
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Fan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-13 00:00:00.000000000 Z
11
+ date: 2022-01-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -19,6 +19,7 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - ".rspec"
21
21
  - ".rubocop.yml"
22
+ - ".yardopts"
22
23
  - CHANGELOG.md
23
24
  - CODE_OF_CONDUCT.md
24
25
  - Gemfile
@@ -38,7 +39,8 @@ licenses:
38
39
  metadata:
39
40
  homepage_uri: https://github.com/NAR8789/qig-ruby
40
41
  source_code_uri: https://github.com/NAR8789/qig-ruby
41
- changelog_uri: https://github.com/NAR8789/qig-ruby/CHANGELOG.txt
42
+ changelog_uri: https://github.com/NAR8789/qig-ruby/blob/main/CHANGELOG.md
43
+ rubygems_mfa_required: 'true'
42
44
  post_install_message:
43
45
  rdoc_options: []
44
46
  require_paths:
@@ -47,7 +49,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
47
49
  requirements:
48
50
  - - ">="
49
51
  - !ruby/object:Gem::Version
50
- version: 2.6.0
52
+ version: 2.7.0
51
53
  required_rubygems_version: !ruby/object:Gem::Requirement
52
54
  requirements:
53
55
  - - ">="