mongoid-shell 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 +7 -0
- data/CHANGELOG.md +8 -3
- data/README.md +6 -6
- data/lib/mongoid/shell/commands/base.rb +5 -9
- data/lib/mongoid/shell/commands/mongo.rb +2 -3
- data/lib/mongoid/shell/commands/mongodump.rb +0 -1
- data/lib/mongoid/shell/commands/mongorestore.rb +7 -3
- data/lib/mongoid/shell/commands/mongostat.rb +1 -1
- data/lib/mongoid/shell/errors/base.rb +44 -46
- data/lib/mongoid/shell/mongoid.rb +7 -0
- data/lib/mongoid/shell/properties/database.rb +0 -2
- data/lib/mongoid/shell/properties/host.rb +5 -3
- data/lib/mongoid/shell/properties/password.rb +9 -4
- data/lib/mongoid/shell/properties/primary.rb +5 -3
- data/lib/mongoid/shell/properties/username.rb +9 -4
- data/lib/mongoid/shell/version.rb +1 -1
- data/lib/mongoid-shell.rb +1 -0
- data/lib/mongoid_shell.rb +0 -1
- metadata +19 -44
- data/.gitignore +0 -4
- data/.rspec +0 -3
- data/.travis.yml +0 -9
- data/Gemfile +0 -9
- data/Rakefile +0 -24
- data/mongoid-shell.gemspec +0 -20
- data/spec/mongoid/commands/base_spec.rb +0 -32
- data/spec/mongoid/commands/mongo_spec.rb +0 -61
- data/spec/mongoid/commands/mongodump_spec.rb +0 -66
- data/spec/mongoid/commands/mongorestore_spec.rb +0 -76
- data/spec/mongoid/commands/mongostat_spec.rb +0 -54
- data/spec/mongoid/mongoid_shell_spec.rb +0 -8
- data/spec/mongoid/properties/host_spec.rb +0 -20
- data/spec/mongoid/properties/primary_spec.rb +0 -20
- data/spec/spec_helper.rb +0 -17
- data/spec/support/config/mongoid.yml +0 -37
- data/spec/support/helpers/moped_session_helper.rb +0 -11
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 64cf2c359ad1afd04b88ccf54613cccc593ea3cc
|
4
|
+
data.tar.gz: bd9aaf637391a1ee1eb1775514ac09b7b567f88d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48dbac68ced2c383aefa39817eac22165073ce1177e4c4ff5dbee81cc867994c005e7559079987a438cb0076077a935e35e8c54be26117e1e3a86f32bd4a6f2f
|
7
|
+
data.tar.gz: de542005f6aa6b91ed3630031b46a62d32cd84de2bc3f5c606a56b13bef0e0430fde73742ad3dce1da33e5c9eeb0bbbea2bfac68d1162a5eab2bf4930c2d32a7
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
0.3.0 (7/1/2014)
|
2
|
+
================
|
3
3
|
|
4
|
-
*
|
4
|
+
* [#3](https://github.com/dblock/mongoid-shell/pull/3): Added Mongoid 4.x support - [@pawelniewie](https://github.com/pawelniewie), [@dblock](https://github.com/dblock).
|
5
|
+
* [#2](https://github.com/dblock/mongoid-shell/pull/2): Added support for `--noIndexRestore` to `Mongoid::Shell::Commands::Mongorestore` - [@macreery](https://github.com/macreery).
|
6
|
+
* [#1](https://github.com/dblock/mongoid-shell/pull/1): Enforced compatibility with Mongoid 3.x only - [@macreery](https://github.com/macreery).
|
7
|
+
* Fix: the `mongorestore` command requires a primary node in a replica set - [@dblock](https://github.com/dblock).
|
8
|
+
* Added Rubocop, Ruby style linter - [@dblock](https://github.com/dblock).
|
9
|
+
* Upgraded to RSpec 3.x expectation syntax - [@dblock](https://github.com/dblock).
|
5
10
|
|
6
11
|
0.2.0 (1/29/2013)
|
7
12
|
=================
|
data/README.md
CHANGED
@@ -32,9 +32,9 @@ system mongodump.to_s # mongodump --db another_database --out /tmp/db_backup
|
|
32
32
|
```
|
33
33
|
|
34
34
|
Supported Commands
|
35
|
-
|
35
|
+
------------------
|
36
36
|
|
37
|
-
|
37
|
+
### Mongo
|
38
38
|
|
39
39
|
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.
|
40
40
|
|
@@ -44,7 +44,7 @@ Mongoid::Shell::Commands::Mongo.new.to_s
|
|
44
44
|
|
45
45
|
Supports `--username`, `--password`, `--eval`, `--nodb`, `--norc`, `--quiet` and `--ipv6`.
|
46
46
|
|
47
|
-
|
47
|
+
### Mongodump
|
48
48
|
|
49
49
|
Mongodump is a utility for creating a binary export of the contents of a database.
|
50
50
|
|
@@ -55,7 +55,7 @@ mongodump.to_s # mongodump --db test --collection test
|
|
55
55
|
|
56
56
|
The `Mongoid::Shell::Commands::Mongodump` class supports `--db`, `--host`, `--username`, `--password`, `--query`, `--out`, `--collection`, `--directoryperdb`, `--journal`, `--oplog`, `--repair`, `--forceTableScan`, `--dbpath` and `--ipv6`.
|
57
57
|
|
58
|
-
|
58
|
+
### Mongorestore
|
59
59
|
|
60
60
|
The mongorestore tool imports content from binary database dump, created by mongodump into a specific database.
|
61
61
|
|
@@ -64,9 +64,9 @@ mongorestore = Mongoid::Shell::Commands::Mongorestore.new({ collection: 'test',
|
|
64
64
|
mongorestore.to_s # mongorestore --db test --collection test /tmp/db_backup
|
65
65
|
```
|
66
66
|
|
67
|
-
The `Mongoid::Shell::Commands::Mongorestore` class supports `--db`, `--host`, `--username`, `--password`, `--collection`, `--ipv6
|
67
|
+
The `Mongoid::Shell::Commands::Mongorestore` class supports `--db`, `--host`, `--username`, `--password`, `--collection`, `--ipv6`, `--dbpath`, `--directoryperdb`, `--journal`, `--objcheck`, `--filter`, `--drop`, `--oplogReplay`, `--keepIndexVersion` and `--noIndexRestore`.
|
68
68
|
|
69
|
-
|
69
|
+
### Mongostat
|
70
70
|
|
71
71
|
The mongostat utility provides a quick overview of the status of a currently running mongod or mongos instance.
|
72
72
|
|
@@ -2,22 +2,19 @@ module Mongoid
|
|
2
2
|
module Shell
|
3
3
|
module Commands
|
4
4
|
class Base
|
5
|
-
|
6
5
|
attr_accessor :session
|
7
6
|
|
8
7
|
class << self
|
9
|
-
|
10
8
|
def command_for(session)
|
11
|
-
|
9
|
+
new(session: session)
|
12
10
|
end
|
13
|
-
|
14
11
|
end
|
15
12
|
|
16
13
|
def initialize(options = nil)
|
17
14
|
options ||= {}
|
18
15
|
options[:session] ||= Mongoid.default_session
|
19
16
|
options.each do |sym, val|
|
20
|
-
|
17
|
+
send "#{sym}=", val
|
21
18
|
end
|
22
19
|
raise Mongoid::Shell::Errors::MissingSessionError unless @session
|
23
20
|
end
|
@@ -28,9 +25,9 @@ module Mongoid
|
|
28
25
|
|
29
26
|
def vargs(args = {})
|
30
27
|
args.map do |key, property|
|
31
|
-
value =
|
28
|
+
value = send(property)
|
32
29
|
next unless value
|
33
|
-
if value.is_a?
|
30
|
+
if value.is_a?(Boolean) || value.is_a?(TrueClass)
|
34
31
|
key
|
35
32
|
else
|
36
33
|
value = value.to_s
|
@@ -42,9 +39,8 @@ module Mongoid
|
|
42
39
|
end
|
43
40
|
|
44
41
|
def to_s
|
45
|
-
[
|
42
|
+
[cmd, vargs].flatten.compact.join(" ")
|
46
43
|
end
|
47
|
-
|
48
44
|
end
|
49
45
|
end
|
50
46
|
end
|
@@ -14,7 +14,7 @@ module Mongoid
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def host_port_and_db
|
17
|
-
[
|
17
|
+
[primary, db].compact.join("/")
|
18
18
|
end
|
19
19
|
|
20
20
|
def vargs
|
@@ -26,10 +26,9 @@ module Mongoid
|
|
26
26
|
'--nodb' => :nodb,
|
27
27
|
'--norc' => :norc,
|
28
28
|
'--quiet' => :quiet,
|
29
|
-
'--ipv6' => :ipv6
|
29
|
+
'--ipv6' => :ipv6
|
30
30
|
})
|
31
31
|
end
|
32
|
-
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|
@@ -2,17 +2,21 @@ module Mongoid
|
|
2
2
|
module Shell
|
3
3
|
module Commands
|
4
4
|
class Mongorestore < Mongoid::Shell::Commands::Base
|
5
|
-
include Mongoid::Shell::Properties::
|
5
|
+
include Mongoid::Shell::Properties::Primary
|
6
6
|
include Mongoid::Shell::Properties::Database
|
7
7
|
include Mongoid::Shell::Properties::Username
|
8
8
|
include Mongoid::Shell::Properties::Password
|
9
9
|
|
10
|
-
attr_accessor :collection, :ipv6, :dbpath, :directoryperdb, :journal, :objcheck, :filter, :drop, :oplogReplay, :keepIndexVersion, :restore
|
10
|
+
attr_accessor :host, :collection, :ipv6, :dbpath, :directoryperdb, :journal, :objcheck, :filter, :drop, :oplogReplay, :keepIndexVersion, :noIndexRestore, :restore
|
11
11
|
|
12
12
|
def initialize(attrs = {})
|
13
13
|
super
|
14
14
|
end
|
15
15
|
|
16
|
+
def host
|
17
|
+
@host || primary
|
18
|
+
end
|
19
|
+
|
16
20
|
def vargs
|
17
21
|
super({
|
18
22
|
'--host' => :host,
|
@@ -29,10 +33,10 @@ module Mongoid
|
|
29
33
|
'--drop' => :drop,
|
30
34
|
'--oplogReplay' => :oplogReplay,
|
31
35
|
'--keepIndexVersion' => :keepIndexVersion,
|
36
|
+
'--noIndexRestore' => :noIndexRestore,
|
32
37
|
'directory or filename to restore from' => :restore
|
33
38
|
})
|
34
39
|
end
|
35
|
-
|
36
40
|
end
|
37
41
|
end
|
38
42
|
end
|
@@ -3,6 +3,7 @@ module Mongoid
|
|
3
3
|
module Commands
|
4
4
|
class Mongostat < Mongoid::Shell::Commands::Base
|
5
5
|
include Mongoid::Shell::Properties::Host
|
6
|
+
include Mongoid::Shell::Properties::Database
|
6
7
|
include Mongoid::Shell::Properties::Username
|
7
8
|
include Mongoid::Shell::Properties::Password
|
8
9
|
|
@@ -24,7 +25,6 @@ module Mongoid
|
|
24
25
|
'--all' => :all
|
25
26
|
})
|
26
27
|
end
|
27
|
-
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -2,7 +2,6 @@ module Mongoid
|
|
2
2
|
module Shell
|
3
3
|
module Errors
|
4
4
|
class Base < StandardError
|
5
|
-
|
6
5
|
# Problem occurred.
|
7
6
|
attr_reader :problem
|
8
7
|
|
@@ -21,60 +20,59 @@ module Mongoid
|
|
21
20
|
@summary = create_summary(key, attributes)
|
22
21
|
@resolution = create_resolution(key, attributes)
|
23
22
|
|
24
|
-
"\nProblem:\n #{@problem}"
|
25
|
-
"\nSummary:\n #{@summary}"
|
23
|
+
"\nProblem:\n #{@problem}" \
|
24
|
+
"\nSummary:\n #{@summary}" \
|
26
25
|
"\nResolution:\n #{@resolution}"
|
27
26
|
end
|
28
27
|
|
29
28
|
private
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
# Given the key of the specific error and the options hash, translate the
|
34
|
-
# message.
|
35
|
-
#
|
36
|
-
# === Parameters
|
37
|
-
# [key] The key of the error in the locales.
|
38
|
-
# [options] The objects to pass to create the message.
|
39
|
-
#
|
40
|
-
# Returns a localized error message string.
|
41
|
-
def translate(key, options)
|
42
|
-
::I18n.translate("#{BASE_KEY}.#{key}", { :locale => :en }.merge(options)).strip
|
43
|
-
end
|
30
|
+
BASE_KEY = "mongoid.shell.errors.messages" #:nodoc:
|
44
31
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
32
|
+
# Given the key of the specific error and the options hash, translate the
|
33
|
+
# message.
|
34
|
+
#
|
35
|
+
# === Parameters
|
36
|
+
# [key] The key of the error in the locales.
|
37
|
+
# [options] The objects to pass to create the message.
|
38
|
+
#
|
39
|
+
# Returns a localized error message string.
|
40
|
+
def translate(key, options)
|
41
|
+
::I18n.translate("#{BASE_KEY}.#{key}", { locale: :en }.merge(options)).strip
|
42
|
+
end
|
55
43
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
44
|
+
# Create the problem.
|
45
|
+
#
|
46
|
+
# === Parameters
|
47
|
+
# [key] The error key.
|
48
|
+
# [attributes] The attributes to interpolate.
|
49
|
+
#
|
50
|
+
# Returns the problem.
|
51
|
+
def create_problem(key, attributes)
|
52
|
+
translate("#{key}.message", attributes)
|
53
|
+
end
|
66
54
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
55
|
+
# Create the summary.
|
56
|
+
#
|
57
|
+
# === Parameters
|
58
|
+
# [key] The error key.
|
59
|
+
# [attributes] The attributes to interpolate.
|
60
|
+
#
|
61
|
+
# Returns the summary.
|
62
|
+
def create_summary(key, attributes)
|
63
|
+
translate("#{key}.summary", attributes)
|
64
|
+
end
|
77
65
|
|
66
|
+
# Create the resolution.
|
67
|
+
#
|
68
|
+
# === Parameters
|
69
|
+
# [key] The error key.
|
70
|
+
# [attributes] The attributes to interpolate.
|
71
|
+
#
|
72
|
+
# Returns the resolution.
|
73
|
+
def create_resolution(key, attributes)
|
74
|
+
translate("#{key}.resolution", attributes)
|
75
|
+
end
|
78
76
|
end
|
79
77
|
end
|
80
78
|
end
|
@@ -2,7 +2,6 @@ module Mongoid
|
|
2
2
|
module Shell
|
3
3
|
module Properties
|
4
4
|
module Host
|
5
|
-
|
6
5
|
attr_accessor :host
|
7
6
|
|
8
7
|
# database host
|
@@ -10,10 +9,13 @@ module Mongoid
|
|
10
9
|
@host || begin
|
11
10
|
node = session.cluster.nodes.first
|
12
11
|
raise Mongoid::Shell::Errors::SessionNotConnectedError unless node
|
13
|
-
|
12
|
+
if Mongoid::Shell.mongoid3?
|
13
|
+
node.address == "localhost:27017" ? nil : node.address
|
14
|
+
else
|
15
|
+
node.address.original == "localhost:27017" ? nil : node.address.original
|
16
|
+
end
|
14
17
|
end
|
15
18
|
end
|
16
|
-
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -2,17 +2,22 @@ module Mongoid
|
|
2
2
|
module Shell
|
3
3
|
module Properties
|
4
4
|
module Password
|
5
|
-
|
6
5
|
attr_accessor :password
|
7
6
|
|
8
7
|
# current password
|
9
8
|
def password
|
10
9
|
@password || begin
|
11
|
-
|
12
|
-
|
10
|
+
if Mongoid::Shell.mongoid3?
|
11
|
+
return nil unless session.context.cluster.auth && session.context.cluster.auth.first
|
12
|
+
session.context.cluster.auth.first[1][1]
|
13
|
+
else
|
14
|
+
node = session.cluster.nodes.first
|
15
|
+
raise Mongoid::Shell::Errors::SessionNotConnectedError unless node
|
16
|
+
return nil if !node.credentials.key?(db) || node.credentials[db].empty?
|
17
|
+
node.credentials[db][1]
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
|
-
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
@@ -2,7 +2,6 @@ module Mongoid
|
|
2
2
|
module Shell
|
3
3
|
module Properties
|
4
4
|
module Primary
|
5
|
-
|
6
5
|
attr_accessor :primary
|
7
6
|
|
8
7
|
# primary database host
|
@@ -11,10 +10,13 @@ module Mongoid
|
|
11
10
|
raise Mongoid::Shell::Errors::SessionNotConnectedError unless session.cluster.nodes.any?
|
12
11
|
node = session.cluster.nodes.find(&:primary?)
|
13
12
|
raise Mongoid::Shell::Errors::MissingPrimaryNodeError unless node
|
14
|
-
|
13
|
+
if Mongoid::Shell.mongoid3?
|
14
|
+
node.address == "localhost:27017" ? nil : node.address
|
15
|
+
else
|
16
|
+
node.address.original == "localhost:27017" ? nil : node.address.original
|
17
|
+
end
|
15
18
|
end
|
16
19
|
end
|
17
|
-
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -2,17 +2,22 @@ module Mongoid
|
|
2
2
|
module Shell
|
3
3
|
module Properties
|
4
4
|
module Username
|
5
|
-
|
6
5
|
attr_accessor :username
|
7
6
|
|
8
7
|
# current username
|
9
8
|
def username
|
10
9
|
@username || begin
|
11
|
-
|
12
|
-
|
10
|
+
if Mongoid::Shell.mongoid3?
|
11
|
+
return nil unless session.context.cluster.auth && session.context.cluster.auth.first
|
12
|
+
session.context.cluster.auth.first[1][0]
|
13
|
+
else
|
14
|
+
node = session.cluster.nodes.first
|
15
|
+
raise Mongoid::Shell::Errors::SessionNotConnectedError unless node
|
16
|
+
return nil if !node.credentials.key?(db) || node.credentials[db].empty?
|
17
|
+
node.credentials[db][0]
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
|
-
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
data/lib/mongoid-shell.rb
CHANGED
@@ -3,6 +3,7 @@ require 'i18n'
|
|
3
3
|
I18n.load_path << File.join(File.dirname(__FILE__), "config", "locales", "en.yml")
|
4
4
|
|
5
5
|
require 'mongoid/shell/version'
|
6
|
+
require 'mongoid/shell/mongoid'
|
6
7
|
require 'mongoid/shell/errors'
|
7
8
|
require 'mongoid/shell/properties'
|
8
9
|
require 'mongoid/shell/commands'
|
data/lib/mongoid_shell.rb
CHANGED
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-shell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Daniel Doubrovkine
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-07-01 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: mongoid
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 3.0.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 3.0.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: i18n
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description:
|
@@ -49,73 +44,53 @@ executables: []
|
|
49
44
|
extensions: []
|
50
45
|
extra_rdoc_files: []
|
51
46
|
files:
|
52
|
-
- .gitignore
|
53
|
-
- .rspec
|
54
|
-
- .travis.yml
|
55
|
-
- CHANGELOG.md
|
56
|
-
- Gemfile
|
57
47
|
- LICENSE.md
|
58
48
|
- README.md
|
59
|
-
-
|
49
|
+
- CHANGELOG.md
|
60
50
|
- lib/config/locales/en.yml
|
61
|
-
- lib/mongoid-shell.rb
|
62
|
-
- lib/mongoid/shell/commands.rb
|
63
51
|
- lib/mongoid/shell/commands/base.rb
|
64
52
|
- lib/mongoid/shell/commands/mongo.rb
|
65
53
|
- lib/mongoid/shell/commands/mongodump.rb
|
66
54
|
- lib/mongoid/shell/commands/mongorestore.rb
|
67
55
|
- lib/mongoid/shell/commands/mongostat.rb
|
68
|
-
- lib/mongoid/shell/
|
56
|
+
- lib/mongoid/shell/commands.rb
|
69
57
|
- lib/mongoid/shell/errors/base.rb
|
70
58
|
- lib/mongoid/shell/errors/missing_primary_node_error.rb
|
71
59
|
- lib/mongoid/shell/errors/missing_session_error.rb
|
72
60
|
- lib/mongoid/shell/errors/session_not_connected_error.rb
|
73
|
-
- lib/mongoid/shell/
|
61
|
+
- lib/mongoid/shell/errors.rb
|
62
|
+
- lib/mongoid/shell/mongoid.rb
|
74
63
|
- lib/mongoid/shell/properties/database.rb
|
75
64
|
- lib/mongoid/shell/properties/host.rb
|
76
65
|
- lib/mongoid/shell/properties/password.rb
|
77
66
|
- lib/mongoid/shell/properties/primary.rb
|
78
67
|
- lib/mongoid/shell/properties/username.rb
|
68
|
+
- lib/mongoid/shell/properties.rb
|
79
69
|
- lib/mongoid/shell/version.rb
|
70
|
+
- lib/mongoid-shell.rb
|
80
71
|
- lib/mongoid_shell.rb
|
81
|
-
- mongoid-shell.gemspec
|
82
|
-
- spec/mongoid/commands/base_spec.rb
|
83
|
-
- spec/mongoid/commands/mongo_spec.rb
|
84
|
-
- spec/mongoid/commands/mongodump_spec.rb
|
85
|
-
- spec/mongoid/commands/mongorestore_spec.rb
|
86
|
-
- spec/mongoid/commands/mongostat_spec.rb
|
87
|
-
- spec/mongoid/mongoid_shell_spec.rb
|
88
|
-
- spec/mongoid/properties/host_spec.rb
|
89
|
-
- spec/mongoid/properties/primary_spec.rb
|
90
|
-
- spec/spec_helper.rb
|
91
|
-
- spec/support/config/mongoid.yml
|
92
|
-
- spec/support/helpers/moped_session_helper.rb
|
93
72
|
homepage: http://github.com/dblock/mongoid-shell
|
94
73
|
licenses:
|
95
74
|
- MIT
|
75
|
+
metadata: {}
|
96
76
|
post_install_message:
|
97
77
|
rdoc_options: []
|
98
78
|
require_paths:
|
99
79
|
- lib
|
100
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
-
none: false
|
102
81
|
requirements:
|
103
|
-
- -
|
82
|
+
- - '>='
|
104
83
|
- !ruby/object:Gem::Version
|
105
84
|
version: '0'
|
106
|
-
segments:
|
107
|
-
- 0
|
108
|
-
hash: 4237627171487641625
|
109
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
-
none: false
|
111
86
|
requirements:
|
112
|
-
- -
|
87
|
+
- - '>='
|
113
88
|
- !ruby/object:Gem::Version
|
114
89
|
version: 1.3.6
|
115
90
|
requirements: []
|
116
91
|
rubyforge_project:
|
117
|
-
rubygems_version: 1.
|
92
|
+
rubygems_version: 2.1.11
|
118
93
|
signing_key:
|
119
|
-
specification_version:
|
94
|
+
specification_version: 4
|
120
95
|
summary: Derive shell commands from Mongoid configuration options.
|
121
96
|
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/gem_tasks'
|
3
|
-
|
4
|
-
require File.expand_path('../lib/mongoid/shell/version', __FILE__)
|
5
|
-
|
6
|
-
begin
|
7
|
-
Bundler.setup(:default, :development)
|
8
|
-
rescue Bundler::BundlerError => e
|
9
|
-
$stderr.puts e.message
|
10
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
11
|
-
exit e.status_code
|
12
|
-
end
|
13
|
-
|
14
|
-
require 'rake'
|
15
|
-
|
16
|
-
require 'rspec/core'
|
17
|
-
require 'rspec/core/rake_task'
|
18
|
-
|
19
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
20
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
21
|
-
end
|
22
|
-
|
23
|
-
task :default => :spec
|
24
|
-
|
data/mongoid-shell.gemspec
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
$:.push File.expand_path("../lib", __FILE__)
|
2
|
-
require "mongoid/shell/version"
|
3
|
-
|
4
|
-
Gem::Specification.new do |s|
|
5
|
-
s.name = "mongoid-shell"
|
6
|
-
s.version = Mongoid::Shell::VERSION
|
7
|
-
s.authors = [ "Daniel Doubrovkine" ]
|
8
|
-
s.email = "dblock@dblock.org"
|
9
|
-
s.platform = Gem::Platform::RUBY
|
10
|
-
s.required_rubygems_version = '>= 1.3.6'
|
11
|
-
s.files = `git ls-files`.split("\n")
|
12
|
-
s.require_paths = [ "lib" ]
|
13
|
-
s.homepage = "http://github.com/dblock/mongoid-shell"
|
14
|
-
s.licenses = [ "MIT" ]
|
15
|
-
s.summary = "Derive shell commands from Mongoid configuration options."
|
16
|
-
s.add_dependency "mongoid"
|
17
|
-
s.add_dependency "i18n"
|
18
|
-
end
|
19
|
-
|
20
|
-
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Shell::Commands::Base do
|
4
|
-
context "without a default session" do
|
5
|
-
before :each do
|
6
|
-
Mongoid.stub(:default_session).and_return(nil)
|
7
|
-
end
|
8
|
-
it "raises an exception when a session is missing" do
|
9
|
-
expect {
|
10
|
-
Mongoid::Shell::Commands::Base.new({})
|
11
|
-
}.to raise_error Mongoid::Shell::Errors::MissingSessionError, /Missing session./
|
12
|
-
end
|
13
|
-
it "raises an exception when options are missing" do
|
14
|
-
expect {
|
15
|
-
Mongoid::Shell::Commands::Base.new(nil)
|
16
|
-
}.to raise_error Mongoid::Shell::Errors::MissingSessionError, /Missing session./
|
17
|
-
end
|
18
|
-
end
|
19
|
-
it "creates a command using the default session" do
|
20
|
-
command = Mongoid::Shell::Commands::Base.new
|
21
|
-
command.session.should eq Mongoid.default_session
|
22
|
-
end
|
23
|
-
it "creates a command using the session provided" do
|
24
|
-
session = Moped::Session.new([ "127.0.0.1:27017" ])
|
25
|
-
command = Mongoid::Shell::Commands::Base.new(session: session)
|
26
|
-
command.session.should eq session
|
27
|
-
end
|
28
|
-
it "command_for" do
|
29
|
-
command = Mongoid::Shell::Commands::Base.command_for(Mongoid.default_session)
|
30
|
-
command.session.should eq Mongoid.default_session
|
31
|
-
end
|
32
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Shell::Commands::Mongo do
|
4
|
-
include MopedSessionHelper
|
5
|
-
context "local" do
|
6
|
-
it "defaults to local" do
|
7
|
-
Mongoid::Shell::Commands::Mongo.new.to_s.should == "mongo mongoid_shell_tests"
|
8
|
-
end
|
9
|
-
it "includes eval" do
|
10
|
-
Mongoid::Shell::Commands::Mongo.new({
|
11
|
-
eval: 'find x'
|
12
|
-
}).to_s.should == 'mongo mongoid_shell_tests --eval "find x"'
|
13
|
-
end
|
14
|
-
it "overrides primary" do
|
15
|
-
Mongoid::Shell::Commands::Mongo.new({
|
16
|
-
eval: 'find x',
|
17
|
-
primary: 'my_primary'
|
18
|
-
}).to_s.should == 'mongo my_primary/mongoid_shell_tests --eval "find x"'
|
19
|
-
end
|
20
|
-
[ :nodb, :norc, :quiet, :ipv6 ].each do |option|
|
21
|
-
it "includes #{option}" do
|
22
|
-
Mongoid::Shell::Commands::Mongo.new({
|
23
|
-
option => true
|
24
|
-
}).to_s.should == "mongo mongoid_shell_tests --#{option}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
context "sessions" do
|
30
|
-
context "default" do
|
31
|
-
before :each do
|
32
|
-
@session = Mongoid::Sessions.with_name(:default)
|
33
|
-
end
|
34
|
-
it "includes username and password" do
|
35
|
-
Mongoid::Shell::Commands::Mongo.new({
|
36
|
-
session: @session
|
37
|
-
}).to_s.should == "mongo mongoid_shell_tests"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
context "a replica set" do
|
41
|
-
before :each do
|
42
|
-
@session = moped_session(:replica_set)
|
43
|
-
end
|
44
|
-
it "includes username and password" do
|
45
|
-
Mongoid::Shell::Commands::Mongo.new({
|
46
|
-
session: @session
|
47
|
-
}).to_s.should == "mongo dedicated1.myapp.com:27017/mongoid --username user --password password"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
context "url" do
|
51
|
-
before :each do
|
52
|
-
@session = moped_session(:url)
|
53
|
-
end
|
54
|
-
it "includes username and password" do
|
55
|
-
Mongoid::Shell::Commands::Mongo.new({
|
56
|
-
session: @session
|
57
|
-
}).to_s.should == "mongo 59.1.22.1:27017/mongoid --username user --password password"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Shell::Commands::Mongodump do
|
4
|
-
include MopedSessionHelper
|
5
|
-
context "local" do
|
6
|
-
it "defaults to local" do
|
7
|
-
Mongoid::Shell::Commands::Mongodump.new.to_s.should == "mongodump --db mongoid_shell_tests"
|
8
|
-
end
|
9
|
-
it "includes collection" do
|
10
|
-
Mongoid::Shell::Commands::Mongodump.new({
|
11
|
-
collection: 'test'
|
12
|
-
}).to_s.should == "mongodump --db mongoid_shell_tests --collection test"
|
13
|
-
end
|
14
|
-
it "includes query" do
|
15
|
-
Mongoid::Shell::Commands::Mongodump.new({
|
16
|
-
query: 'find x'
|
17
|
-
}).to_s.should == 'mongodump --db mongoid_shell_tests --query "find x"'
|
18
|
-
end
|
19
|
-
[ :out, :dbpath ].each do |option|
|
20
|
-
it "includes #{option}" do
|
21
|
-
Mongoid::Shell::Commands::Mongodump.new({
|
22
|
-
option => '/this is a folder'
|
23
|
-
}).to_s.should == "mongodump --db mongoid_shell_tests --#{option} \"/this is a folder\""
|
24
|
-
end
|
25
|
-
end
|
26
|
-
[ :directoryperdb, :journal, :oplog, :repair, :forceTableScan, :dbpath, :ipv6 ].each do |option|
|
27
|
-
it "includes #{option}" do
|
28
|
-
Mongoid::Shell::Commands::Mongodump.new({
|
29
|
-
option => true
|
30
|
-
}).to_s.should == "mongodump --db mongoid_shell_tests --#{option}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
context "sessions" do
|
35
|
-
context "default" do
|
36
|
-
before :each do
|
37
|
-
@session = moped_session(:default)
|
38
|
-
end
|
39
|
-
it "includes username and password" do
|
40
|
-
Mongoid::Shell::Commands::Mongodump.new({
|
41
|
-
session: @session
|
42
|
-
}).to_s.should == "mongodump --db mongoid_shell_tests"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
context "a replica set" do
|
46
|
-
before :each do
|
47
|
-
@session = moped_session(:replica_set)
|
48
|
-
end
|
49
|
-
it "includes username and password" do
|
50
|
-
Mongoid::Shell::Commands::Mongodump.new({
|
51
|
-
session: @session
|
52
|
-
}).to_s.should == "mongodump --host dedicated1.myapp.com:27017 --db mongoid --username user --password password"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
context "url" do
|
56
|
-
before :each do
|
57
|
-
@session = moped_session(:url)
|
58
|
-
end
|
59
|
-
it "includes username and password" do
|
60
|
-
Mongoid::Shell::Commands::Mongodump.new({
|
61
|
-
session: @session
|
62
|
-
}).to_s.should == "mongodump --host 59.1.22.1:27017 --db mongoid --username user --password password"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Shell::Commands::Mongorestore do
|
4
|
-
include MopedSessionHelper
|
5
|
-
context "local" do
|
6
|
-
it "defaults to local" do
|
7
|
-
Mongoid::Shell::Commands::Mongorestore.new.to_s.should == "mongorestore --db mongoid_shell_tests"
|
8
|
-
end
|
9
|
-
it "includes collection" do
|
10
|
-
Mongoid::Shell::Commands::Mongorestore.new({
|
11
|
-
collection: 'test',
|
12
|
-
restore: 'folder'
|
13
|
-
}).to_s.should == "mongorestore --db mongoid_shell_tests --collection test folder"
|
14
|
-
end
|
15
|
-
it "can override the database, username, password and host" do
|
16
|
-
Mongoid::Shell::Commands::Mongorestore.new({
|
17
|
-
host: 'my_host',
|
18
|
-
username: 'my_username',
|
19
|
-
password: 'my_password',
|
20
|
-
collection: 'test',
|
21
|
-
db: 'my_db',
|
22
|
-
restore: 'folder'
|
23
|
-
}).to_s.should == "mongorestore --host my_host --db my_db --username my_username --password my_password --collection test folder"
|
24
|
-
end
|
25
|
-
[ :collection, :dbpath, :filter ].each do |option|
|
26
|
-
it "includes #{option}" do
|
27
|
-
Mongoid::Shell::Commands::Mongorestore.new({
|
28
|
-
option => 'var arg',
|
29
|
-
restore: 'a folder'
|
30
|
-
}).to_s.should == "mongorestore --db mongoid_shell_tests --#{option} \"var arg\" \"a folder\""
|
31
|
-
end
|
32
|
-
end
|
33
|
-
[ :ipv6, :directoryperdb, :journal, :objcheck, :drop, :oplogReplay, :keepIndexVersion ].each do |option|
|
34
|
-
it "includes #{option}" do
|
35
|
-
Mongoid::Shell::Commands::Mongorestore.new({
|
36
|
-
option => true
|
37
|
-
}).to_s.should == "mongorestore --db mongoid_shell_tests --#{option}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
context "sessions" do
|
42
|
-
context "default" do
|
43
|
-
before :each do
|
44
|
-
@session = moped_session(:default)
|
45
|
-
end
|
46
|
-
it "includes username and password" do
|
47
|
-
Mongoid::Shell::Commands::Mongorestore.new({
|
48
|
-
session: @session,
|
49
|
-
restore: "a folder"
|
50
|
-
}).to_s.should == "mongorestore --db mongoid_shell_tests \"a folder\""
|
51
|
-
end
|
52
|
-
end
|
53
|
-
context "a replica set" do
|
54
|
-
before :each do
|
55
|
-
@session = moped_session(:replica_set)
|
56
|
-
end
|
57
|
-
it "includes username and password" do
|
58
|
-
Mongoid::Shell::Commands::Mongorestore.new({
|
59
|
-
session: @session,
|
60
|
-
restore: "a folder"
|
61
|
-
}).to_s.should == "mongorestore --host dedicated1.myapp.com:27017 --db mongoid --username user --password password \"a folder\""
|
62
|
-
end
|
63
|
-
end
|
64
|
-
context "url" do
|
65
|
-
before :each do
|
66
|
-
@session = moped_session(:url)
|
67
|
-
end
|
68
|
-
it "includes username and password" do
|
69
|
-
Mongoid::Shell::Commands::Mongorestore.new({
|
70
|
-
session: @session,
|
71
|
-
restore: "a folder"
|
72
|
-
}).to_s.should == "mongorestore --host 59.1.22.1:27017 --db mongoid --username user --password password \"a folder\""
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Shell::Commands::Mongostat do
|
4
|
-
include MopedSessionHelper
|
5
|
-
context "local" do
|
6
|
-
it "defaults to local" do
|
7
|
-
Mongoid::Shell::Commands::Mongostat.new.to_s.should == "mongostat"
|
8
|
-
end
|
9
|
-
it "rowcount" do
|
10
|
-
Mongoid::Shell::Commands::Mongostat.new({
|
11
|
-
:rowcount => 10
|
12
|
-
}).to_s.should == "mongostat --rowcount 10"
|
13
|
-
end
|
14
|
-
[ :http, :discover, :all, :noheaders ].each do |option|
|
15
|
-
it "includes #{option}" do
|
16
|
-
Mongoid::Shell::Commands::Mongostat.new({
|
17
|
-
option => true
|
18
|
-
}).to_s.should == "mongostat --#{option}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
context "sessions" do
|
23
|
-
context "default" do
|
24
|
-
before :each do
|
25
|
-
@session = Mongoid::Sessions.with_name(:default)
|
26
|
-
end
|
27
|
-
it "includes username and password" do
|
28
|
-
Mongoid::Shell::Commands::Mongostat.new({
|
29
|
-
session: @session
|
30
|
-
}).to_s.should == "mongostat"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
context "a replica set" do
|
34
|
-
before :each do
|
35
|
-
@session = moped_session(:replica_set)
|
36
|
-
end
|
37
|
-
it "includes username and password" do
|
38
|
-
Mongoid::Shell::Commands::Mongostat.new({
|
39
|
-
session: @session
|
40
|
-
}).to_s.should == "mongostat --host dedicated1.myapp.com:27017 --username user --password password"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
context "url" do
|
44
|
-
before :each do
|
45
|
-
@session = moped_session(:url)
|
46
|
-
end
|
47
|
-
it "includes username and password" do
|
48
|
-
Mongoid::Shell::Commands::Mongostat.new({
|
49
|
-
session: @session
|
50
|
-
}).to_s.should == "mongostat --host 59.1.22.1:27017 --username user --password password"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Shell::Properties::Host do
|
4
|
-
subject do
|
5
|
-
klass = Class.new do
|
6
|
-
include Mongoid::Shell::Properties::Host
|
7
|
-
|
8
|
-
def session
|
9
|
-
Mongoid.default_session
|
10
|
-
end
|
11
|
-
end
|
12
|
-
klass.new
|
13
|
-
end
|
14
|
-
it "raises an exception when the session is not connected" do
|
15
|
-
Mongoid.default_session.cluster.stub(:nodes).and_return([])
|
16
|
-
expect {
|
17
|
-
subject.host
|
18
|
-
}.to raise_error Mongoid::Shell::Errors::SessionNotConnectedError, /Session is not connected./
|
19
|
-
end
|
20
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Shell::Properties::Primary do
|
4
|
-
subject do
|
5
|
-
klass = Class.new do
|
6
|
-
include Mongoid::Shell::Properties::Primary
|
7
|
-
|
8
|
-
def session
|
9
|
-
Mongoid.default_session
|
10
|
-
end
|
11
|
-
end
|
12
|
-
klass.new
|
13
|
-
end
|
14
|
-
it "raises an exception when the session is not connected" do
|
15
|
-
Mongoid.default_session.cluster.nodes.first.stub(:primary?).and_return(false)
|
16
|
-
expect {
|
17
|
-
subject.primary
|
18
|
-
}.to raise_error Mongoid::Shell::Errors::MissingPrimaryNodeError, /Session does not have a primary node./
|
19
|
-
end
|
20
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'rspec'
|
6
|
-
require 'mongoid'
|
7
|
-
require 'mongoid-shell'
|
8
|
-
|
9
|
-
[ "support/helpers/*.rb" ].each do |path|
|
10
|
-
Dir["#{File.dirname(__FILE__)}/#{path}"].each do |file|
|
11
|
-
require file
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
Mongoid.configure do |config|
|
16
|
-
config.connect_to('mongoid_shell_tests')
|
17
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# Tell Mongoid which environment this configuration is for.
|
2
|
-
production:
|
3
|
-
# This starts the session configuration settings. You may have as
|
4
|
-
# many sessions as you like, but you must have at least 1 named
|
5
|
-
# 'default'.
|
6
|
-
sessions:
|
7
|
-
# Define the default session.
|
8
|
-
default:
|
9
|
-
# A session can have any number of hosts. Usually 1 for a single
|
10
|
-
# server setup, and at least 3 for a replica set. Hosts must be
|
11
|
-
# an array of host:port pairs. This session is single server.
|
12
|
-
hosts:
|
13
|
-
- flame.mongohq.com:27017
|
14
|
-
# Define the default database name.
|
15
|
-
database: mongoid
|
16
|
-
# Since this database points at a session connected to MongoHQ, we must
|
17
|
-
# provide the authentication details.
|
18
|
-
username: user
|
19
|
-
password: password
|
20
|
-
# This defines a secondary session at a replica set.
|
21
|
-
replica_set:
|
22
|
-
# This configuration is a 3 node replica set.
|
23
|
-
hosts:
|
24
|
-
- dedicated1.myapp.com:27017
|
25
|
-
- dedicated2.myapp.com:27017
|
26
|
-
- dedicated3.myapp.com:27017
|
27
|
-
database: mongoid
|
28
|
-
# We can set session specific options, like reads executing
|
29
|
-
# on secondary nodes, and defaulting the session to safe mode.
|
30
|
-
options:
|
31
|
-
consistency: :eventual
|
32
|
-
safe: true
|
33
|
-
username: user
|
34
|
-
password: password
|
35
|
-
# This configuration shows an authenticated replica set via a uri.
|
36
|
-
url:
|
37
|
-
uri: mongodb://user:password@59.1.22.1:27017,59.1.22.2:27017/mongoid
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module MopedSessionHelper
|
2
|
-
# returns a Moped session with stubbed address resolution
|
3
|
-
def moped_session(name)
|
4
|
-
config = File.join(File.dirname(__FILE__), "../../support/config/mongoid.yml")
|
5
|
-
Mongoid.load! config, :production
|
6
|
-
Moped::Node.any_instance.stub(:resolve_address)
|
7
|
-
session = Mongoid::Sessions.with_name(name)
|
8
|
-
session.cluster.nodes.last.stub(:primary?).and_return(true)
|
9
|
-
session
|
10
|
-
end
|
11
|
-
end
|