mongoid-shell 0.5.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f3fcabc0004e2cacdcac5776ed0d39e594708ec4ec152540b067bd1888dc527
4
- data.tar.gz: 38d3a660fb2dfc72dada952faa2e46d692d5cfe0bf36588572932c76d51975eb
3
+ metadata.gz: caa302a6929ce5b0953f7909336d13ced51e1149bcbf57564afa8fb39407cb54
4
+ data.tar.gz: 9476f5a48754a1d426006be1c366999e0ca1ff8cc961f6c1bb41e9a50cfae96d
5
5
  SHA512:
6
- metadata.gz: 8ffbf1bad9524352f98cd3a8bf1d98e544b9c428580442b85b108fa50de25cf4189e081a1639ab886e710fe60200d1c118dd46ee1c8be7eebe8e757d1371ba48
7
- data.tar.gz: 5b6d190569e9d18542b651658c2b4b8bc58ca836536ac6f54ec6071a5163b19c28b6764fd436f4145c210d989904a0dd3ba7400e099785844593172e79e38135
6
+ metadata.gz: f7b26e08e9b89e8f2a9e9d0f43c49b35d9701b379e81ac12cf8b2b8a992f356154915e59896ca88305c68eed3653446b9e510bbcfee05f9c3104014152e11f64
7
+ data.tar.gz: 151c8c5436158fdb0d9629dd797232eb6198aaa91e422ec7c64b5a12b1fb87b863e375bee396cdda5dff032897206e5e7118c22e34c978c39bef1c319139792a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ### 0.5.2 (2026/11/24)
2
+
3
+ * [#27](https://github.com/mongoid/mongoid-shell/pull/27): Expand command rendering, error, and entrypoint tests and combine coverage across supported Mongoid versions - [@dblock](https://github.com/dblock).
4
+ * [#29](https://github.com/mongoid/mongoid-shell/pull/29): Lint Markdown, YAML, and spelling with rubocop-md, rubocop-prose, rubocop-spellcheck, and rubocop-yaml in a separate Lint workflow, and clean up documentation - [@dblock](https://github.com/dblock).
5
+ * [#30](https://github.com/mongoid/mongoid-shell/pull/30): Run tests only on default-branch pushes and pull requests, cancel superseded pull request runs, skip duplicate lint in the test matrix, and bound job times - [@dblock](https://github.com/dblock).
6
+ * [#31](https://github.com/mongoid/mongoid-shell/pull/31): Release with ruby-gem-release from a manually dispatched GitHub Actions workflow using RubyGems Trusted Publishing, with dry runs - [@dblock](https://github.com/dblock).
7
+ * [#33](https://github.com/mongoid/mongoid-shell/pull/33): Ignore `vendor/bundle` so the release workflow's clean-checkout check passes after `bundler-cache` installs gems - [@dblock](https://github.com/dblock).
8
+ * [#34](https://github.com/mongoid/mongoid-shell/pull/34): Upgrade danger-pr-comment to 0.3.0 from the `danger` organization, skip empty Danger report comments, and require current Danger gems - [@dblock](https://github.com/dblock).
9
+
10
+ ### 0.5.1 (2026/10/15)
11
+
12
+ * [#17](https://github.com/mongoid/mongoid-shell/issues/17): Preserve Extended JSON queries through shell escaping and serialize Hash queries for `mongodump` and `mongoexport` - [@dblock](https://github.com/dblock).
13
+
1
14
  ### 0.5.0 (2026/10/14)
2
15
 
3
16
  * [#25](https://github.com/mongoid/mongoid-shell/pull/25): Add SimpleCov and Coveralls reporting in CI and update status badges - [@dblock](https://github.com/dblock).
data/README.md CHANGED
@@ -1,22 +1,26 @@
1
- Mongoid::Shell
2
- ==============
1
+ # Mongoid::Shell
3
2
 
4
- [![Gem Version](https://badge.fury.io/rb/mongoid-shell.svg)](https://badge.fury.io/rb/mongoid-shell)
5
- [![Test](https://github.com/mongoid/mongoid-shell/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/mongoid/mongoid-shell/actions/workflows/test.yml)
6
- [![Rubocop](https://github.com/mongoid/mongoid-shell/actions/workflows/rubocop.yml/badge.svg?branch=master)](https://github.com/mongoid/mongoid-shell/actions/workflows/rubocop.yml)
7
- [![Coverage Status](https://coveralls.io/repos/github/mongoid/mongoid-shell/badge.svg?branch=master)](https://coveralls.io/github/mongoid/mongoid-shell?branch=master)
8
-
9
- CI collects SimpleCov coverage on Ruby 3.4 with Mongoid 9 and MongoDB 8.0 and submits one report to Coveralls using GitHub's workflow token. To generate a local report, run `COVERAGE=true MONGOID_VERSION=9 bundle install` followed by `COVERAGE=true MONGOID_VERSION=9 bundle exec rake spec`. Reports are written to `coverage/`.
3
+ [![Gem Version](https://badge.fury.io/rb/mongoid-shell.svg)](https://badge.fury.io/rb/mongoid-shell) [![Test](https://github.com/mongoid/mongoid-shell/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/mongoid/mongoid-shell/actions/workflows/test.yml) [![Lint](https://github.com/mongoid/mongoid-shell/actions/workflows/lint.yml/badge.svg?branch=master)](https://github.com/mongoid/mongoid-shell/actions/workflows/lint.yml) [![Coverage Status](https://coveralls.io/repos/github/mongoid/mongoid-shell/badge.svg?branch=master)](https://coveralls.io/github/mongoid/mongoid-shell?branch=master)
10
4
 
11
5
  Create mongo command-lines from Mongoid configuration.
12
6
 
7
+ ## Installation
8
+
9
+ Add the gem to your Gemfile and run `bundle install`.
10
+
11
+ ```ruby
12
+ gem 'mongoid-shell'
13
+ ```
14
+
15
+ ## Usage
16
+
13
17
  For example, connect to your production database without having to remember the entire command line using a `db:production:shell` Rake task.
14
18
 
15
- ``` ruby
16
- namespace :db
17
- namespace :production
18
- task :shell
19
- Mongoid.load! File.join(Rails.root, "config/mongoid.yml"), :production
19
+ ```ruby
20
+ namespace :db do
21
+ namespace :production do
22
+ task :shell do
23
+ Mongoid.load! File.join(Rails.root, 'config/mongoid.yml'), :production
20
24
  system Mongoid::Shell::Commands::Mongo.new.to_s
21
25
  end
22
26
  end
@@ -25,14 +29,14 @@ end
25
29
 
26
30
  Commands can be created for the current default session or you can pass a session as an argument to a new command.
27
31
 
28
- ``` ruby
32
+ ```ruby
29
33
  Mongoid::Shell::Commands::Mongodump.new # will use Mongoid.default_session
30
- Mongoid::Shell::Commands::Mongodump.new(session: Moped::Session.new([ "127.0.0.1:27017" ]))
34
+ Mongoid::Shell::Commands::Mongodump.new(session: Moped::Session.new(['127.0.0.1:27017']))
31
35
  ```
32
36
 
33
37
  Commands accept parameters.
34
38
 
35
- ``` ruby
39
+ ```ruby
36
40
  out = File.join(Dir.tmpdir, 'db_backup')
37
41
  mongodump = Mongoid::Shell::Commands::Mongodump.new(db: 'another_database', out: out)
38
42
  system mongodump.to_s # mongodump --db another_database --out /tmp/db_backup
@@ -40,34 +44,32 @@ system mongodump.to_s # mongodump --db another_database --out /tmp/db_backup
40
44
 
41
45
  To specify parameters multiple times, set them to arrays.
42
46
 
43
- ``` ruby
44
- mongodump = Mongoid::Shell::Commands::Mongodump.new(excludeCollection: %w(users products))
47
+ ```ruby
48
+ mongodump = Mongoid::Shell::Commands::Mongodump.new(excludeCollection: %w[users products])
45
49
  system mongodump.to_s # mongodump --excludeCollection users --excludeCollection products
46
50
  ```
47
51
 
48
52
  To use output in logs, pass the `mask_sensitive` option to `to_s`.
49
53
 
50
- ``` ruby
51
- > Mongoid::Shell::Commands::Mongo.new.to_s(mask_sensitive: true)
52
- => "mongo 59.1.22.1:27017/mongoid --username user --password ********"
54
+ ```ruby
55
+ Mongoid::Shell::Commands::Mongo.new.to_s(mask_sensitive: true)
56
+ # => "mongo 59.1.22.1:27017/mongoid --username user --password ********"
53
57
 
54
- > Mongoid::Shell::Commands::Mongo.new.to_s(mask_sensitive: '(masked)')
55
- => "mongo 59.1.22.1:27017/mongoid --username user --password (masked)"
58
+ Mongoid::Shell::Commands::Mongo.new.to_s(mask_sensitive: '(masked)')
59
+ # => "mongo 59.1.22.1:27017/mongoid --username user --password (masked)"
56
60
  ```
57
61
 
58
- Compatibility
59
- -------------
62
+ ## Compatibility
60
63
 
61
64
  This gem supports Mongoid 3, 4, 5, 6, 7, 8 and 9.
62
65
 
63
- Supported Commands
64
- ------------------
66
+ ## Supported Commands
65
67
 
66
68
  ### Mongo
67
69
 
68
70
  The mongo shell is an interactive JavaScript shell for MongoDB. The `Mongoid::Shell::Commands::Mongo` class generates a command line to connect to MongoDB. A particularly useful feature is that it will always yield the address of the master node of a MongoDB replica set.
69
71
 
70
- ``` ruby
72
+ ```ruby
71
73
  Mongoid::Shell::Commands::Mongo.new.to_s
72
74
  ```
73
75
 
@@ -77,18 +79,28 @@ Supports `--username`, `--password`, `--eval`, `--nodb`, `--norc`, `--quiet`, `-
77
79
 
78
80
  Mongodump is a utility for creating a binary export of the contents of a database.
79
81
 
80
- ``` ruby
82
+ ```ruby
81
83
  mongodump = Mongoid::Shell::Commands::Mongodump.new(collection: 'test')
82
84
  mongodump.to_s # mongodump --db test --collection test
83
85
  ```
84
86
 
85
87
  The `Mongoid::Shell::Commands::Mongodump` class supports `--db`, `--host`, `--username`, `--password`, `--query`, `--out`, `--collection`, `--excludeCollection`, `--excludeCollectionsWithPrefix`, `--directoryperdb`, `--journal`, `--oplog`, `--repair`, `--forceTableScan`, `--dbpath`, `--ipv6`, `--ssl` and `--authenticationDatabase`
86
88
 
89
+ For `mongodump` and `mongoexport`, `query` accepts an Extended JSON string or a Hash containing Extended JSON values. Hashes are serialized as JSON and queries are shell-escaped, preserving operators such as `$eq` and `$date` literally.
90
+
91
+ ```ruby
92
+ mongodump = Mongoid::Shell::Commands::Mongodump.new(
93
+ collection: 'history_trackers',
94
+ query: { scope: { '$eq' => 'offer' }, created_at: { '$gte' => { '$date' => '2019-12-24T09:36:56.312Z' } } }
95
+ )
96
+ system mongodump.to_s
97
+ ```
98
+
87
99
  ### Mongorestore
88
100
 
89
101
  The mongorestore tool imports content from binary database dump, created by mongodump into a specific database.
90
102
 
91
- ``` ruby
103
+ ```ruby
92
104
  mongorestore = Mongoid::Shell::Commands::Mongorestore.new(collection: 'test', restore: '/tmp/db_backup')
93
105
  mongorestore.to_s # mongorestore --db test --collection test /tmp/db_backup
94
106
  ```
@@ -99,7 +111,7 @@ The `Mongoid::Shell::Commands::Mongorestore` class supports `--db`, `--host`, `-
99
111
 
100
112
  The mongoexport tool produces a JSON or CSV export of data stored in a MongoDB instance.
101
113
 
102
- ``` ruby
114
+ ```ruby
103
115
  mongoexport = Mongoid::Shell::Commands::Mongoexport.new(collection: 'traffic', out: 'traffic.json')
104
116
  mongoexport.to_s # mongoexport --db test --collection traffic --out traffic.json
105
117
  ```
@@ -110,8 +122,7 @@ The `Mongoid::Shell::Commands::Mongoexport` class supports `--verbose`, `--quiet
110
122
 
111
123
  The mongoimport tool imports content from an Extended JSON, CSV, or TSV export created by mongoexport, or potentially, another third-party export tool.
112
124
 
113
-
114
- ``` ruby
125
+ ```ruby
115
126
  mongoimport = Mongoid::Shell::Commands::Mongoimport.new(collection: 'contacts', file: 'contacts.json')
116
127
  mongoimport.to_s # mongoimport --db test --collection contacts --file contacts.json
117
128
  ```
@@ -124,14 +135,12 @@ The mongostat utility provides a quick overview of the status of a currently run
124
135
 
125
136
  The `Mongoid::Shell::Commands::Mongostat` class supports `--host`, `--username`, `--password`, `--rowcount`, `--discover`, `--noheaders`, `--http`, `--all`, `--ssl` and `--authenticationDatabase`.
126
137
 
127
- Contributing
128
- ------------
138
+ ## Contributing
129
139
 
130
- Fork the project. Make your feature addition or bug fix with tests. Send a pull request. Bonus points for topic branches.
140
+ See [CONTRIBUTING.md](CONTRIBUTING.md), [CHANGELOG.md](CHANGELOG.md), and [RELEASING.md](RELEASING.md).
131
141
 
132
- Copyright and License
133
- ---------------------
142
+ ## License
134
143
 
135
- MIT License, see [LICENSE](http://github.com/mongoid/mongoid-shell/raw/master/LICENSE.md) for details.
144
+ MIT License, see [LICENSE.md](LICENSE.md) for details.
136
145
 
137
- (c) 2013-2026 [Daniel Doubrovkine](http://github.com/dblock), [Artsy Inc.](http://artsy.net)
146
+ (c) 2013-2026 [Daniel Doubrovkine](https://github.com/dblock), [Artsy Inc.](https://www.artsy.net)
@@ -60,13 +60,7 @@ module Mongoid
60
60
  when Boolean, TrueClass then key
61
61
  when Array then value.map { |v| "#{key} #{v}" }.join(' ')
62
62
  else
63
- if mask_sensitive && arg[:sensitive]
64
- value = mask_sensitive
65
- else
66
- # TODO: quote other special characters?
67
- value = value.to_s
68
- value = "\"#{value}\"" if value.include? ' '
69
- end
63
+ value = format_value(value, arg, mask_sensitive)
70
64
  key ? "#{key} #{value}" : value
71
65
  end
72
66
  end
@@ -78,6 +72,18 @@ module Mongoid
78
72
 
79
73
  private
80
74
 
75
+ def format_value(value, arg, mask_sensitive)
76
+ return mask_sensitive if mask_sensitive && arg[:sensitive]
77
+
78
+ if arg[:json]
79
+ value = ::JSON.generate(value) if value.is_a?(Hash)
80
+ Shellwords.escape(value.to_s)
81
+ else
82
+ value = value.to_s
83
+ value.include?(' ') ? "\"#{value}\"" : value
84
+ end
85
+ end
86
+
81
87
  if ::Mongoid::Compatibility::Version.mongoid5_or_newer?
82
88
  def default_client_or_session
83
89
  Mongoid.default_client
@@ -18,7 +18,7 @@ module Mongoid
18
18
  option :collection
19
19
  option :excludeCollection
20
20
  option :excludeCollectionsWithPrefix
21
- option :query
21
+ option :query, json: true
22
22
  option :out
23
23
  option :directoryperdb
24
24
  option :journal
@@ -26,7 +26,7 @@ module Mongoid
26
26
  option :collection
27
27
  option :fields
28
28
  option :fieldFile
29
- option :query
29
+ option :query, json: true
30
30
  option :type
31
31
  option :out
32
32
  option :skip
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Mongoid
4
4
  module Shell
5
- VERSION = '0.5.0'
5
+ VERSION = '0.5.2'
6
6
  end
7
7
  end
data/lib/mongoid-shell.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'i18n'
4
+ require 'json'
5
+ require 'shellwords'
4
6
 
5
7
  I18n.load_path << File.join(File.dirname(__FILE__), 'config', 'locales', 'en.yml')
6
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-15 00:00:00.000000000 Z
11
+ date: 2026-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: 1.3.6
108
108
  requirements: []
109
- rubygems_version: 3.5.16
109
+ rubygems_version: 3.5.22
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Derive shell commands from Mongoid configuration options.