monq 0.1.0 → 0.1.2
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/AGENTS.md +55 -0
- data/lib/monq/ext/array.rb +8 -8
- data/lib/monq/ext/criteria.rb +6 -6
- data/lib/monq/ext/document.rb +6 -6
- data/lib/monq/ext/view.rb +6 -6
- data/lib/monq/ext.rb +26 -2
- data/lib/monq/presenter.rb +9 -1
- data/lib/monq/version.rb +1 -1
- metadata +18 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 549e91e0850eef71c43ad692ffb4ad92c6c5bbb4b43a7d834bf2ee690a3384f4
|
|
4
|
+
data.tar.gz: 5e2c84dacf04271206add867dd75df819d2bc5ccfc37d429e991ad271e3f3487
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d762f5a51e8a52f47c2deb2ef4ef1d5f6b09d41f492f1c483aa8b73574fcf436603fa694ff68b791717c491a9a19689dd14cb288ca2f966aed714e23ea742464
|
|
7
|
+
data.tar.gz: f0dcabaa63dcdc853594b30312ae091e35a84af2c980a47840f2801882f266f04462b79b9c4fe31e22a47d813f9d2275b8d2e5404e7f37f12afd88f506583a11
|
data/AGENTS.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
monq 是发布到 RubyGems(<https://rubygems.org>)的 Ruby gem,用 Bundler 管理。
|
|
4
|
+
|
|
5
|
+
## 版本号
|
|
6
|
+
|
|
7
|
+
唯一来源是 `lib/monq/version.rb` 中的 `Monq::VERSION`,`monq.gemspec` 从这里读取。
|
|
8
|
+
不要在 gemspec 里写死版本号。
|
|
9
|
+
|
|
10
|
+
## 升级版本号:`gem bump`
|
|
11
|
+
|
|
12
|
+
`gem bump` 由 [gem-release](https://github.com/svenfuchs/gem-release) 提供:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
gem bump # 默认升 patch:0.1.0 -> 0.1.1
|
|
16
|
+
gem bump --version minor # 升 minor:0.1.0 -> 0.2.0
|
|
17
|
+
gem bump --version major # 升 major:0.1.0 -> 1.0.0
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
注意:
|
|
21
|
+
|
|
22
|
+
- 本机的 gem-release(2.2.x)中,`gem bump` **默认会自动创建 commit**
|
|
23
|
+
(提交消息为 `Bump monq to x.y.z`,仅含 `version.rb`),可用 `--no-commit` 关闭。
|
|
24
|
+
- `Gemfile.lock` 里固定了 monq 自身版本,bump 后会过期。
|
|
25
|
+
运行一次 `bundle install`(或任意 `bundle exec` 命令)即可自动刷新,
|
|
26
|
+
之后把 `Gemfile.lock` 单独提交。
|
|
27
|
+
|
|
28
|
+
## 发布到 RubyGems:`rake release`
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
rake release
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`rake release` 由 Rakefile 中的 `bundler/gem_tasks` 提供,它会依次:
|
|
35
|
+
|
|
36
|
+
1. 构建 gem 到 `pkg/monq-<version>.gem`;
|
|
37
|
+
2. 创建 `v<version>` 标签(如 `v0.1.1`)并 push 到 git origin;
|
|
38
|
+
3. 执行 `gem push` 把 `.gem` 推送到 <https://rubygems.org>。
|
|
39
|
+
|
|
40
|
+
前置条件:
|
|
41
|
+
|
|
42
|
+
- 工作区必须干净——包括 `gem bump` 的改动在内的所有变更都要先 commit,
|
|
43
|
+
否则 release 会中止;
|
|
44
|
+
- 本机已配置 rubygems.org 的 `gem push` 凭据;
|
|
45
|
+
- RubyGems 不允许重复推送同一版本号,重发前必须先 bump。
|
|
46
|
+
|
|
47
|
+
## 完整流程示例
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
bundle exec rspec # 发布前先跑测试
|
|
51
|
+
gem bump # 升 patch 版本并自动提交 version.rb
|
|
52
|
+
bundle install # 刷新 Gemfile.lock 中 monq 自身版本
|
|
53
|
+
git add Gemfile.lock && git commit -m "chore: update Gemfile.lock"
|
|
54
|
+
rake release # 构建、打 tag、推送到 RubyGems
|
|
55
|
+
```
|
data/lib/monq/ext/array.rb
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class Array
|
|
4
|
-
def t
|
|
5
|
-
puts Monq::Ext.table_for(hash_docs)
|
|
4
|
+
def t(*attrs, **options)
|
|
5
|
+
puts Monq::Ext.table_for(Monq::Ext.filter_docs(hash_docs, attrs, options))
|
|
6
6
|
nil
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def v
|
|
10
|
-
Monq::Ext.vertical(hash_docs)
|
|
9
|
+
def v(*attrs, **options)
|
|
10
|
+
Monq::Ext.vertical(Monq::Ext.filter_docs(hash_docs, attrs, options))
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
# visidata comes later; always print the table so vd works without the binary.
|
|
14
|
-
def vd
|
|
15
|
-
t
|
|
14
|
+
def vd(*attrs, **options)
|
|
15
|
+
t(*attrs, **options)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def write_csv(filename)
|
|
@@ -22,7 +22,7 @@ class Array
|
|
|
22
22
|
csv = CSV.new(file)
|
|
23
23
|
return if docs.empty?
|
|
24
24
|
|
|
25
|
-
keys = docs
|
|
25
|
+
keys = Monq::Presenter.column_names(docs)
|
|
26
26
|
csv << keys.map(&:to_s)
|
|
27
27
|
docs.each { |row| csv << keys.map { |k| row[k].to_s } }
|
|
28
28
|
end
|
|
@@ -35,7 +35,7 @@ class Array
|
|
|
35
35
|
package.workbook.add_worksheet(name: sheet_name) do |sheet|
|
|
36
36
|
next if docs.empty?
|
|
37
37
|
|
|
38
|
-
keys = docs
|
|
38
|
+
keys = Monq::Presenter.column_names(docs)
|
|
39
39
|
sheet.add_row(keys.map(&:to_s))
|
|
40
40
|
docs.each { |row| sheet.add_row(keys.map { |k| row[k].to_s }) }
|
|
41
41
|
end
|
data/lib/monq/ext/criteria.rb
CHANGED
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
module Monq
|
|
4
4
|
module Ext
|
|
5
5
|
module Criteria
|
|
6
|
-
def t
|
|
7
|
-
Monq::Ext.display_criteria(self)
|
|
6
|
+
def t(*attrs, **options)
|
|
7
|
+
Monq::Ext.display_criteria(self, attrs, options)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def v
|
|
10
|
+
def v(*attrs, **options)
|
|
11
11
|
docs, = Monq::Ext.materialize(self)
|
|
12
|
-
docs.v
|
|
12
|
+
docs.v(*attrs, **options)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def vd
|
|
16
|
-
t
|
|
15
|
+
def vd(*attrs, **options)
|
|
16
|
+
t(*attrs, **options)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
# Full result set. Display methods cap at 500; export must not.
|
data/lib/monq/ext/document.rb
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
module Monq
|
|
4
4
|
module Ext
|
|
5
5
|
module Document
|
|
6
|
-
def t
|
|
7
|
-
[attributes].t
|
|
6
|
+
def t(*attrs, **options)
|
|
7
|
+
[attributes].t(*attrs, **options)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def v
|
|
11
|
-
[attributes].v
|
|
10
|
+
def v(*attrs, **options)
|
|
11
|
+
[attributes].v(*attrs, **options)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def vd
|
|
15
|
-
[attributes].vd
|
|
14
|
+
def vd(*attrs, **options)
|
|
15
|
+
[attributes].vd(*attrs, **options)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def write_csv(filename)
|
data/lib/monq/ext/view.rb
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
module Monq
|
|
4
4
|
module Ext
|
|
5
5
|
module View
|
|
6
|
-
def t
|
|
7
|
-
materialized_docs.t
|
|
6
|
+
def t(*attrs, **options)
|
|
7
|
+
materialized_docs.t(*attrs, **options)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def v
|
|
11
|
-
materialized_docs.v
|
|
10
|
+
def v(*attrs, **options)
|
|
11
|
+
materialized_docs.v(*attrs, **options)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def vd
|
|
15
|
-
materialized_docs.vd
|
|
14
|
+
def vd(*attrs, **options)
|
|
15
|
+
materialized_docs.vd(*attrs, **options)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
# Full result set. Display methods cap at 500; export must not.
|
data/lib/monq/ext.rb
CHANGED
|
@@ -10,9 +10,9 @@ module Monq
|
|
|
10
10
|
[criteria.to_a, capped]
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def self.display_criteria(criteria)
|
|
13
|
+
def self.display_criteria(criteria, attrs = [], options = {})
|
|
14
14
|
docs, capped = materialize(criteria)
|
|
15
|
-
puts table_for(docs)
|
|
15
|
+
puts table_for(filter_docs(docs, attrs, options))
|
|
16
16
|
puts "showing #{docs.size} rows (capped at #{CAP})" if capped
|
|
17
17
|
nil
|
|
18
18
|
end
|
|
@@ -33,6 +33,30 @@ module Monq
|
|
|
33
33
|
[keys, nil, *rows[1..]]
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
+
def self.filter_docs(docs, attrs = [], options = {})
|
|
37
|
+
return docs if docs.empty?
|
|
38
|
+
|
|
39
|
+
column_names = Presenter.column_names(docs)
|
|
40
|
+
unless docs.first.is_a?(Hash) || !docs.first.respond_to?(:attributes)
|
|
41
|
+
docs = docs.map(&:attributes)
|
|
42
|
+
end
|
|
43
|
+
return docs if attrs.empty? && !options[:except]
|
|
44
|
+
|
|
45
|
+
selected = attrs.flat_map { |e| e.is_a?(Regexp) ? column_names.grep(e) : e }.uniq
|
|
46
|
+
|
|
47
|
+
if options[:except]
|
|
48
|
+
selected = column_names if selected.empty?
|
|
49
|
+
except = options[:except]
|
|
50
|
+
if except.is_a?(Regexp)
|
|
51
|
+
selected.reject! { |e| e =~ except }
|
|
52
|
+
else
|
|
53
|
+
selected -= [except].flatten
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
docs.map { |doc| doc.slice(*selected) }
|
|
58
|
+
end
|
|
59
|
+
|
|
36
60
|
def self.limit_unset?(options)
|
|
37
61
|
return true if options.nil?
|
|
38
62
|
|
data/lib/monq/presenter.rb
CHANGED
|
@@ -28,11 +28,19 @@ module Monq
|
|
|
28
28
|
def rows(docs)
|
|
29
29
|
return [] if docs.nil? || docs.empty?
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
docs = docs.map { |doc| doc.is_a?(Hash) || !doc.respond_to?(:attributes) ? doc : doc.attributes }
|
|
32
|
+
keys = column_names(docs)
|
|
32
33
|
body = docs.map { |doc| keys.map { |key| scalar(doc[key]) } }
|
|
33
34
|
[keys, *body]
|
|
34
35
|
end
|
|
35
36
|
|
|
37
|
+
# Union of keys across all docs: Mongoid documents only carry the fields
|
|
38
|
+
# actually stored on each one, so any single doc (e.g. the oldest row in a
|
|
39
|
+
# natural-order cursor) can miss fields present in the rest.
|
|
40
|
+
def column_names(docs)
|
|
41
|
+
docs.flat_map { |doc| doc.is_a?(Hash) || !doc.respond_to?(:attributes) ? doc.keys : doc.attributes.keys }.uniq
|
|
42
|
+
end
|
|
43
|
+
|
|
36
44
|
def as_json_tree(value)
|
|
37
45
|
case value
|
|
38
46
|
when BSON::ObjectId, BSON::Decimal128
|
data/lib/monq/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: monq
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Liu Xiang
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: mongoid
|
|
@@ -24,6 +23,20 @@ dependencies:
|
|
|
24
23
|
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '9.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: csv
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
27
40
|
- !ruby/object:Gem::Dependency
|
|
28
41
|
name: pry
|
|
29
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -130,6 +143,7 @@ executables:
|
|
|
130
143
|
extensions: []
|
|
131
144
|
extra_rdoc_files: []
|
|
132
145
|
files:
|
|
146
|
+
- AGENTS.md
|
|
133
147
|
- CODE_OF_CONDUCT.md
|
|
134
148
|
- LICENSE.txt
|
|
135
149
|
- README.md
|
|
@@ -171,7 +185,6 @@ metadata:
|
|
|
171
185
|
allowed_push_host: https://rubygems.org
|
|
172
186
|
homepage_uri: https://github.com/lululau/monq
|
|
173
187
|
source_code_uri: https://github.com/lululau/monq
|
|
174
|
-
post_install_message:
|
|
175
188
|
rdoc_options: []
|
|
176
189
|
require_paths:
|
|
177
190
|
- lib
|
|
@@ -186,8 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
186
199
|
- !ruby/object:Gem::Version
|
|
187
200
|
version: '0'
|
|
188
201
|
requirements: []
|
|
189
|
-
rubygems_version:
|
|
190
|
-
signing_key:
|
|
202
|
+
rubygems_version: 4.0.3
|
|
191
203
|
specification_version: 4
|
|
192
204
|
summary: Mongoid + Pry MongoDB query workbench
|
|
193
205
|
test_files: []
|