qig 0.2.0 → 0.3.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/.rubocop.yml +1 -1
- data/CHANGELOG.md +23 -1
- data/Gemfile.lock +1 -1
- data/README.md +11 -7
- data/lib/qig/version.rb +1 -1
- data/lib/qig.rb +56 -13
- data/qig.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f92505d2904e0032d3fcd5b33f03540a7ce8d09080bc50a534ede7e2daecf686
|
4
|
+
data.tar.gz: 16caa89894a03819be080591bd729b89ddfb743712122fff401b18e2e2ba0ae9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab2d2ace58c87bc6117a20d9ca2e6b1d329398cd5ce895fb2f206abb5f66a06782b4f8d3d48716719e2a67f7091f6e938aebc9bc7e329652782583952b82533a
|
7
|
+
data.tar.gz: 9362297e8f6feb6a9f390302ae7d12093877fdd3215f5894b366a05b41330093479b027745b6579ff546bba4f27a79f539d5f985ed89c1a87c07d663acdbe9c7
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
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
|
+
|
1
23
|
# 0.2.0 (January 14, 2022)
|
2
24
|
|
3
25
|
## Features
|
@@ -33,4 +55,4 @@
|
|
33
55
|
## Features
|
34
56
|
|
35
57
|
- Ability to qig into arrays and hashes
|
36
|
-
- Value iteration (`[]`) over arrays
|
58
|
+
- Value iteration (`[]`) over arrays
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -7,13 +7,17 @@ qig is dig extended with jq's "value iterator" `[]` operator.
|
|
7
7
|
|
8
8
|
## Features
|
9
9
|
|
10
|
-
- [x]
|
11
|
-
- [x] qig into
|
12
|
-
- [x] qig into
|
13
|
-
- [
|
14
|
-
- [
|
15
|
-
- [x]
|
16
|
-
- [x]
|
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
|
17
21
|
- [ ] option to monkey patch this for more dig-like `subject.qig(*path)` syntax
|
18
22
|
|
19
23
|
## Installation
|
data/lib/qig/version.rb
CHANGED
data/lib/qig.rb
CHANGED
@@ -14,33 +14,76 @@ module Qig
|
|
14
14
|
unit_qig(subject, *path)
|
15
15
|
end
|
16
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
|
26
|
+
|
17
27
|
private
|
18
28
|
|
19
|
-
def unit_qig(subject, *path)
|
29
|
+
def unit_qig(subject, *path) # rubocop:disable Metrics/MethodLength
|
20
30
|
head, *rest = path
|
21
31
|
case head
|
22
|
-
|
32
|
+
in nil
|
23
33
|
subject
|
24
|
-
|
25
|
-
|
26
|
-
|
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'
|
27
48
|
else
|
28
|
-
unit_qig(subject
|
49
|
+
unit_qig(step(subject, head), *rest)
|
29
50
|
end
|
30
51
|
end
|
31
52
|
|
32
|
-
def collection_qig(subjects, *path)
|
53
|
+
def collection_qig(subjects, *path) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
33
54
|
head, *rest = path
|
34
55
|
case head
|
35
|
-
|
56
|
+
in nil
|
36
57
|
subjects
|
37
|
-
|
38
|
-
collection_qig(subjects.map
|
39
|
-
|
40
|
-
|
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)
|
41
76
|
else
|
42
|
-
collection_qig(subjects.map { |
|
77
|
+
collection_qig(subjects.map { |s| step(s, head) }, *rest)
|
43
78
|
end
|
44
79
|
end
|
80
|
+
|
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
|
87
|
+
end
|
45
88
|
end
|
46
89
|
end
|
data/qig.gemspec
CHANGED
@@ -12,7 +12,7 @@ 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.
|
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
|
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.
|
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-
|
11
|
+
date: 2022-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -49,7 +49,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
49
|
requirements:
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: 2.
|
52
|
+
version: 2.7.0
|
53
53
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
55
|
- - ">="
|