monq 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: '049e17df27a39b7710e1793ad8aa2bbceea1cac5781c952c604f05569e0c5e3a'
4
- data.tar.gz: 2d1b3d71bfbf2f666116004d75cc96963576d10570926788672a8943774a814a
3
+ metadata.gz: bdf67f2d8ba19bd24e12b8d7a5397ca27a800a37925eebb1c584f40f05b9af1f
4
+ data.tar.gz: aa19a699c514ede037e1663f326a74cd6dd9ab77096255125eaa5a77c5583629
5
5
  SHA512:
6
- metadata.gz: b40814534a5516dd367c70a706500df2b3ca91a5313eb1544c94ddc05204e247ddc33ff54b8934731f748454dc149b4dacb924894eaf073e90684e49a9c5f86f
7
- data.tar.gz: 7260f9a2eeb283c07a7bd4e19755897afbc44a4267896b1b58518256749bb0ffe5dd2479296cd20eef38e67b610f3304946fed4ddccb4cf7e96e7467e22721bb
6
+ metadata.gz: 446339b7b3cd119046fce6473ff03ae6ca294bfe642d0ea1e637306b9bbe4eb1674bf5b9d369bcc00ea4c0cb8a276efbe96e571bb146b5258765fe34e8e3851d
7
+ data.tar.gz: 73da4e7fb09de97340e482641198ee3a5635413a385cb45813250ce807ccd8d6483eb8a9bbfd74ecd149fbabfc7062b0b4457ba9daa89dbee4bc93f8bbeaed94
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
+ ```
@@ -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)
@@ -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.
@@ -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,28 @@ module Monq
33
33
  [keys, nil, *rows[1..]]
34
34
  end
35
35
 
36
+ def self.filter_docs(docs, attrs = [], options = {})
37
+ unless docs.empty? || docs.first.is_a?(Hash) || !docs.first.respond_to?(:attributes)
38
+ docs = docs.map(&:attributes)
39
+ end
40
+ return docs if docs.empty? || (attrs.empty? && !options[:except])
41
+
42
+ column_names = docs.first.keys
43
+ selected = attrs.flat_map { |e| e.is_a?(Regexp) ? column_names.grep(e) : e }.uniq
44
+
45
+ if options[:except]
46
+ selected = column_names if selected.empty?
47
+ except = options[:except]
48
+ if except.is_a?(Regexp)
49
+ selected.reject! { |e| e =~ except }
50
+ else
51
+ selected -= [except].flatten
52
+ end
53
+ end
54
+
55
+ docs.map { |doc| doc.slice(*selected) }
56
+ end
57
+
36
58
  def self.limit_unset?(options)
37
59
  return true if options.nil?
38
60
 
@@ -28,6 +28,7 @@ module Monq
28
28
  def rows(docs)
29
29
  return [] if docs.nil? || docs.empty?
30
30
 
31
+ docs = docs.map { |doc| doc.is_a?(Hash) || !doc.respond_to?(:attributes) ? doc : doc.attributes }
31
32
  keys = docs.first.keys
32
33
  body = docs.map { |doc| keys.map { |key| scalar(doc[key]) } }
33
34
  [keys, *body]
data/lib/monq/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Monq
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Xiang
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2026-10-25 00:00:00.000000000 Z
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: 3.4.1
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: []