mongoid-shell 0.3.0 → 0.4.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/CHANGELOG.md +5 -0
- data/README.md +11 -1
- data/lib/mongoid-shell.rb +2 -2
- data/lib/mongoid/shell/commands/base.rb +15 -3
- data/lib/mongoid/shell/commands/mongo.rb +1 -1
- data/lib/mongoid/shell/errors/base.rb +1 -1
- data/lib/mongoid/shell/errors/missing_primary_node_error.rb +1 -1
- data/lib/mongoid/shell/errors/missing_session_error.rb +1 -1
- data/lib/mongoid/shell/errors/session_not_connected_error.rb +1 -1
- data/lib/mongoid/shell/properties/database.rb +8 -2
- data/lib/mongoid/shell/properties/host.rb +22 -8
- data/lib/mongoid/shell/properties/password.rb +19 -5
- data/lib/mongoid/shell/properties/primary.rb +25 -9
- data/lib/mongoid/shell/properties/username.rb +19 -5
- data/lib/mongoid/shell/version.rb +1 -1
- metadata +22 -9
- data/lib/mongoid/shell/mongoid.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8e2171bae62ea69cca115b3e565481d8eec2264
|
4
|
+
data.tar.gz: 2a23dce764d1c449c36710985a57c4f0b21665da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a6595709848647bca1f6f917b4203db842ec600e8241896f042fd5edfbc32ac1bfce69cf98505feac096e9da8ed85c35ff4a310b2d347a09ee443d9ed610aee
|
7
|
+
data.tar.gz: 9bd96b1f707fc37caca976d2c0c17a633231c4f9251cf1f1b04d12312aa9b4e828f922ce387cf7b1f8e8e83b1205b3202da1d8ac5f5d138a23b4c4a06c8c0124
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
-
Mongoid::Shell
|
1
|
+
Mongoid::Shell
|
2
2
|
==============
|
3
3
|
|
4
|
+
[](http://badge.fury.io/rb/mongoid-shell)
|
5
|
+
[](https://travis-ci.org/dblock/mongoid-shell)
|
6
|
+
[](https://gemnasium.com/dblock/mongoid-shell)
|
7
|
+
[](https://codeclimate.com/github/dblock/mongoid-shell)
|
8
|
+
|
4
9
|
Create mongo command-lines from Mongoid configuration.
|
5
10
|
|
6
11
|
For example, connect to your production database without having to remember the entire command line using a `db:production:shell` Rake task.
|
@@ -31,6 +36,11 @@ mongodump = Mongoid::Shell::Commands::Mongodump.new(db: 'another_database', out:
|
|
31
36
|
system mongodump.to_s # mongodump --db another_database --out /tmp/db_backup
|
32
37
|
```
|
33
38
|
|
39
|
+
Compatibility
|
40
|
+
-------------
|
41
|
+
|
42
|
+
This gem supports Mongoid 3, 4 and 5.
|
43
|
+
|
34
44
|
Supported Commands
|
35
45
|
------------------
|
36
46
|
|
data/lib/mongoid-shell.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'i18n'
|
2
2
|
|
3
|
-
I18n.load_path << File.join(File.dirname(__FILE__),
|
3
|
+
I18n.load_path << File.join(File.dirname(__FILE__), 'config', 'locales', 'en.yml')
|
4
4
|
|
5
|
+
require 'mongoid/compatibility'
|
5
6
|
require 'mongoid/shell/version'
|
6
|
-
require 'mongoid/shell/mongoid'
|
7
7
|
require 'mongoid/shell/errors'
|
8
8
|
require 'mongoid/shell/properties'
|
9
9
|
require 'mongoid/shell/commands'
|
@@ -12,11 +12,11 @@ module Mongoid
|
|
12
12
|
|
13
13
|
def initialize(options = nil)
|
14
14
|
options ||= {}
|
15
|
-
options[:session] ||=
|
15
|
+
options[:session] ||= default_client_or_session
|
16
16
|
options.each do |sym, val|
|
17
17
|
send "#{sym}=", val
|
18
18
|
end
|
19
|
-
|
19
|
+
fail Mongoid::Shell::Errors::MissingSessionError unless @session
|
20
20
|
end
|
21
21
|
|
22
22
|
def cmd
|
@@ -39,7 +39,19 @@ module Mongoid
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def to_s
|
42
|
-
[cmd, vargs].flatten.compact.join(
|
42
|
+
[cmd, vargs].flatten.compact.join(' ')
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
if ::Mongoid::Compatibility::Version.mongoid3? || ::Mongoid::Compatibility::Version.mongoid4?
|
48
|
+
def default_client_or_session
|
49
|
+
Mongoid.default_session
|
50
|
+
end
|
51
|
+
else
|
52
|
+
def default_client_or_session
|
53
|
+
Mongoid.default_client
|
54
|
+
end
|
43
55
|
end
|
44
56
|
end
|
45
57
|
end
|
@@ -5,8 +5,14 @@ module Mongoid
|
|
5
5
|
attr_accessor :db
|
6
6
|
|
7
7
|
# current database name
|
8
|
-
|
9
|
-
|
8
|
+
if ::Mongoid::Compatibility::Version.mongoid3? || ::Mongoid::Compatibility::Version.mongoid4?
|
9
|
+
def db
|
10
|
+
@db || session.send(:current_database).name
|
11
|
+
end
|
12
|
+
else
|
13
|
+
def db
|
14
|
+
@db || session.database.name
|
15
|
+
end
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|
@@ -5,14 +5,28 @@ module Mongoid
|
|
5
5
|
attr_accessor :host
|
6
6
|
|
7
7
|
# database host
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
node.address ==
|
14
|
-
|
15
|
-
|
8
|
+
if ::Mongoid::Compatibility::Version.mongoid3?
|
9
|
+
def host
|
10
|
+
@host || begin
|
11
|
+
node = session.cluster.nodes.first
|
12
|
+
fail Mongoid::Shell::Errors::SessionNotConnectedError unless node
|
13
|
+
node.address == 'localhost:27017' ? nil : node.address
|
14
|
+
end
|
15
|
+
end
|
16
|
+
elsif ::Mongoid::Compatibility::Version.mongoid4?
|
17
|
+
def host
|
18
|
+
@host || begin
|
19
|
+
node = session.cluster.nodes.first
|
20
|
+
fail Mongoid::Shell::Errors::SessionNotConnectedError unless node
|
21
|
+
node.address.original == 'localhost:27017' ? nil : node.address.original
|
22
|
+
end
|
23
|
+
end
|
24
|
+
else
|
25
|
+
def host
|
26
|
+
@host || begin
|
27
|
+
node = session.cluster.servers.first
|
28
|
+
fail Mongoid::Shell::Errors::SessionNotConnectedError unless node
|
29
|
+
node.address.to_s == 'localhost:27017' ? nil : node.address.to_s
|
16
30
|
end
|
17
31
|
end
|
18
32
|
end
|
@@ -5,18 +5,32 @@ module Mongoid
|
|
5
5
|
attr_accessor :password
|
6
6
|
|
7
7
|
# current password
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
if ::Mongoid::Compatibility::Version.mongoid3?
|
9
|
+
def password
|
10
|
+
@password || begin
|
11
11
|
return nil unless session.context.cluster.auth && session.context.cluster.auth.first
|
12
12
|
session.context.cluster.auth.first[1][1]
|
13
|
-
|
13
|
+
end
|
14
|
+
end
|
15
|
+
elsif ::Mongoid::Compatibility::Version.mongoid4?
|
16
|
+
def password
|
17
|
+
@password || begin
|
14
18
|
node = session.cluster.nodes.first
|
15
|
-
|
19
|
+
fail Mongoid::Shell::Errors::SessionNotConnectedError unless node
|
16
20
|
return nil if !node.credentials.key?(db) || node.credentials[db].empty?
|
17
21
|
node.credentials[db][1]
|
18
22
|
end
|
19
23
|
end
|
24
|
+
else
|
25
|
+
def password
|
26
|
+
@password || begin
|
27
|
+
server = session.cluster.servers.first
|
28
|
+
fail Mongoid::Shell::Errors::SessionNotConnectedError unless server
|
29
|
+
server.context.with_connection do |connection|
|
30
|
+
connection.options[:password]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
20
34
|
end
|
21
35
|
end
|
22
36
|
end
|
@@ -5,15 +5,31 @@ module Mongoid
|
|
5
5
|
attr_accessor :primary
|
6
6
|
|
7
7
|
# primary database host
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
node.address ==
|
15
|
-
|
16
|
-
|
8
|
+
if ::Mongoid::Compatibility::Version.mongoid3?
|
9
|
+
def primary
|
10
|
+
@primary || begin
|
11
|
+
fail Mongoid::Shell::Errors::SessionNotConnectedError unless session.cluster.nodes.any?
|
12
|
+
node = session.cluster.nodes.find(&:primary?)
|
13
|
+
fail Mongoid::Shell::Errors::MissingPrimaryNodeError unless node
|
14
|
+
node.address == 'localhost:27017' ? nil : node.address
|
15
|
+
end
|
16
|
+
end
|
17
|
+
elsif ::Mongoid::Compatibility::Version.mongoid4?
|
18
|
+
def primary
|
19
|
+
@primary || begin
|
20
|
+
fail Mongoid::Shell::Errors::SessionNotConnectedError unless session.cluster.nodes.any?
|
21
|
+
node = session.cluster.nodes.find(&:primary?)
|
22
|
+
fail Mongoid::Shell::Errors::MissingPrimaryNodeError unless node
|
23
|
+
node.address.original == 'localhost:27017' ? nil : node.address.original
|
24
|
+
end
|
25
|
+
end
|
26
|
+
else
|
27
|
+
def primary
|
28
|
+
@primary || begin
|
29
|
+
fail Mongoid::Shell::Errors::SessionNotConnectedError unless session.cluster.servers.any?
|
30
|
+
node = session.cluster.servers.find { |server| server.primary? || server.standalone? }
|
31
|
+
fail Mongoid::Shell::Errors::MissingPrimaryNodeError unless node
|
32
|
+
node.address.to_s == 'localhost:27017' ? nil : node.address.to_s
|
17
33
|
end
|
18
34
|
end
|
19
35
|
end
|
@@ -5,18 +5,32 @@ module Mongoid
|
|
5
5
|
attr_accessor :username
|
6
6
|
|
7
7
|
# current username
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
if ::Mongoid::Compatibility::Version.mongoid3?
|
9
|
+
def username
|
10
|
+
@username || begin
|
11
11
|
return nil unless session.context.cluster.auth && session.context.cluster.auth.first
|
12
12
|
session.context.cluster.auth.first[1][0]
|
13
|
-
|
13
|
+
end
|
14
|
+
end
|
15
|
+
elsif ::Mongoid::Compatibility::Version.mongoid4?
|
16
|
+
def username
|
17
|
+
@username || begin
|
14
18
|
node = session.cluster.nodes.first
|
15
|
-
|
19
|
+
fail Mongoid::Shell::Errors::SessionNotConnectedError unless node
|
16
20
|
return nil if !node.credentials.key?(db) || node.credentials[db].empty?
|
17
21
|
node.credentials[db][0]
|
18
22
|
end
|
19
23
|
end
|
24
|
+
else
|
25
|
+
def username
|
26
|
+
@username || begin
|
27
|
+
server = session.cluster.servers.first
|
28
|
+
fail Mongoid::Shell::Errors::SessionNotConnectedError unless server
|
29
|
+
server.context.with_connection do |connection|
|
30
|
+
connection.options[:user]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
20
34
|
end
|
21
35
|
end
|
22
36
|
end
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -38,36 +38,49 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mongoid-compatibility
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description:
|
42
56
|
email: dblock@dblock.org
|
43
57
|
executables: []
|
44
58
|
extensions: []
|
45
59
|
extra_rdoc_files: []
|
46
60
|
files:
|
61
|
+
- CHANGELOG.md
|
47
62
|
- LICENSE.md
|
48
63
|
- README.md
|
49
|
-
- CHANGELOG.md
|
50
64
|
- lib/config/locales/en.yml
|
65
|
+
- lib/mongoid-shell.rb
|
66
|
+
- lib/mongoid/shell/commands.rb
|
51
67
|
- lib/mongoid/shell/commands/base.rb
|
52
68
|
- lib/mongoid/shell/commands/mongo.rb
|
53
69
|
- lib/mongoid/shell/commands/mongodump.rb
|
54
70
|
- lib/mongoid/shell/commands/mongorestore.rb
|
55
71
|
- lib/mongoid/shell/commands/mongostat.rb
|
56
|
-
- lib/mongoid/shell/
|
72
|
+
- lib/mongoid/shell/errors.rb
|
57
73
|
- lib/mongoid/shell/errors/base.rb
|
58
74
|
- lib/mongoid/shell/errors/missing_primary_node_error.rb
|
59
75
|
- lib/mongoid/shell/errors/missing_session_error.rb
|
60
76
|
- lib/mongoid/shell/errors/session_not_connected_error.rb
|
61
|
-
- lib/mongoid/shell/
|
62
|
-
- lib/mongoid/shell/mongoid.rb
|
77
|
+
- lib/mongoid/shell/properties.rb
|
63
78
|
- lib/mongoid/shell/properties/database.rb
|
64
79
|
- lib/mongoid/shell/properties/host.rb
|
65
80
|
- lib/mongoid/shell/properties/password.rb
|
66
81
|
- lib/mongoid/shell/properties/primary.rb
|
67
82
|
- lib/mongoid/shell/properties/username.rb
|
68
|
-
- lib/mongoid/shell/properties.rb
|
69
83
|
- lib/mongoid/shell/version.rb
|
70
|
-
- lib/mongoid-shell.rb
|
71
84
|
- lib/mongoid_shell.rb
|
72
85
|
homepage: http://github.com/dblock/mongoid-shell
|
73
86
|
licenses:
|
@@ -89,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
102
|
version: 1.3.6
|
90
103
|
requirements: []
|
91
104
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
105
|
+
rubygems_version: 2.4.5
|
93
106
|
signing_key:
|
94
107
|
specification_version: 4
|
95
108
|
summary: Derive shell commands from Mongoid configuration options.
|