mongoid-shell 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64cf2c359ad1afd04b88ccf54613cccc593ea3cc
4
- data.tar.gz: bd9aaf637391a1ee1eb1775514ac09b7b567f88d
3
+ metadata.gz: b8e2171bae62ea69cca115b3e565481d8eec2264
4
+ data.tar.gz: 2a23dce764d1c449c36710985a57c4f0b21665da
5
5
  SHA512:
6
- metadata.gz: 48dbac68ced2c383aefa39817eac22165073ce1177e4c4ff5dbee81cc867994c005e7559079987a438cb0076077a935e35e8c54be26117e1e3a86f32bd4a6f2f
7
- data.tar.gz: de542005f6aa6b91ed3630031b46a62d32cd84de2bc3f5c606a56b13bef0e0430fde73742ad3dce1da33e5c9eeb0bbbea2bfac68d1162a5eab2bf4930c2d32a7
6
+ metadata.gz: 5a6595709848647bca1f6f917b4203db842ec600e8241896f042fd5edfbc32ac1bfce69cf98505feac096e9da8ed85c35ff4a310b2d347a09ee443d9ed610aee
7
+ data.tar.gz: 9bd96b1f707fc37caca976d2c0c17a633231c4f9251cf1f1b04d12312aa9b4e828f922ce387cf7b1f8e8e83b1205b3202da1d8ac5f5d138a23b4c4a06c8c0124
@@ -1,3 +1,8 @@
1
+ 0.4.0 (10/20/2015)
2
+ ==================
3
+
4
+ * [#6](https://github.com/dblock/mongoid-shell/pull/6) - Compatibility with Mongoid 5.x - [@dblock](https://github.com/dblock).
5
+
1
6
  0.3.0 (7/1/2014)
2
7
  ================
3
8
 
data/README.md CHANGED
@@ -1,6 +1,11 @@
1
- Mongoid::Shell [![Build Status](https://travis-ci.org/dblock/mongoid-shell.png?branch=master)](https://travis-ci.org/dblock/mongoid-shell)
1
+ Mongoid::Shell
2
2
  ==============
3
3
 
4
+ [![Gem Version](http://img.shields.io/gem/v/mongoid-shell.svg)](http://badge.fury.io/rb/mongoid-shell)
5
+ [![Build Status](http://img.shields.io/travis/dblock/mongoid-shell.svg)](https://travis-ci.org/dblock/mongoid-shell)
6
+ [![Dependency Status](https://gemnasium.com/dblock/mongoid-shell.svg)](https://gemnasium.com/dblock/mongoid-shell)
7
+ [![Code Climate](https://codeclimate.com/github/dblock/mongoid-shell.svg)](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
 
@@ -1,9 +1,9 @@
1
1
  require 'i18n'
2
2
 
3
- I18n.load_path << File.join(File.dirname(__FILE__), "config", "locales", "en.yml")
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] ||= Mongoid.default_session
15
+ options[:session] ||= default_client_or_session
16
16
  options.each do |sym, val|
17
17
  send "#{sym}=", val
18
18
  end
19
- raise Mongoid::Shell::Errors::MissingSessionError unless @session
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
@@ -14,7 +14,7 @@ module Mongoid
14
14
  end
15
15
 
16
16
  def host_port_and_db
17
- [primary, db].compact.join("/")
17
+ [primary, db].compact.join('/')
18
18
  end
19
19
 
20
20
  def vargs
@@ -27,7 +27,7 @@ module Mongoid
27
27
 
28
28
  private
29
29
 
30
- BASE_KEY = "mongoid.shell.errors.messages" #:nodoc:
30
+ BASE_KEY = 'mongoid.shell.errors.messages' #:nodoc:
31
31
 
32
32
  # Given the key of the specific error and the options hash, translate the
33
33
  # message.
@@ -3,7 +3,7 @@ module Mongoid
3
3
  module Errors
4
4
  class MissingPrimaryNodeError < Mongoid::Shell::Errors::Base
5
5
  def initialize
6
- super(compose_message("missing_primary_node"))
6
+ super(compose_message('missing_primary_node'))
7
7
  end
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module Mongoid
3
3
  module Errors
4
4
  class MissingSessionError < Mongoid::Shell::Errors::Base
5
5
  def initialize
6
- super(compose_message("missing_session"))
6
+ super(compose_message('missing_session'))
7
7
  end
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module Mongoid
3
3
  module Errors
4
4
  class SessionNotConnectedError < Mongoid::Shell::Errors::Base
5
5
  def initialize
6
- super(compose_message("session_not_connected"))
6
+ super(compose_message('session_not_connected'))
7
7
  end
8
8
  end
9
9
  end
@@ -5,8 +5,14 @@ module Mongoid
5
5
  attr_accessor :db
6
6
 
7
7
  # current database name
8
- def db
9
- @db || session.send(:current_database).name
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
- def host
9
- @host || begin
10
- node = session.cluster.nodes.first
11
- raise Mongoid::Shell::Errors::SessionNotConnectedError unless node
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
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
- def password
9
- @password || begin
10
- if Mongoid::Shell.mongoid3?
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
- else
13
+ end
14
+ end
15
+ elsif ::Mongoid::Compatibility::Version.mongoid4?
16
+ def password
17
+ @password || begin
14
18
  node = session.cluster.nodes.first
15
- raise Mongoid::Shell::Errors::SessionNotConnectedError unless node
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
- def primary
9
- @primary || begin
10
- raise Mongoid::Shell::Errors::SessionNotConnectedError unless session.cluster.nodes.any?
11
- node = session.cluster.nodes.find(&:primary?)
12
- raise Mongoid::Shell::Errors::MissingPrimaryNodeError unless node
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
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
- def username
9
- @username || begin
10
- if Mongoid::Shell.mongoid3?
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
- else
13
+ end
14
+ end
15
+ elsif ::Mongoid::Compatibility::Version.mongoid4?
16
+ def username
17
+ @username || begin
14
18
  node = session.cluster.nodes.first
15
- raise Mongoid::Shell::Errors::SessionNotConnectedError unless node
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
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Shell
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  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.3.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: 2014-07-01 00:00:00.000000000 Z
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/commands.rb
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/errors.rb
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.1.11
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.
@@ -1,7 +0,0 @@
1
- module Mongoid
2
- module Shell
3
- def self.mongoid3?
4
- ::Mongoid.const_defined? :Observer # deprecated in Mongoid 4.x
5
- end
6
- end
7
- end