mongoid 1.9.2 → 1.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/mongoid/config.rb +30 -16
  2. data/lib/mongoid/version.rb +1 -1
  3. metadata +10 -10
@@ -78,8 +78,8 @@ module Mongoid #:nodoc
78
78
  alias :database :master
79
79
  alias :database= :master=
80
80
 
81
- # Sets the Mongo::DB slave databases to be used. If the objects trying to me
82
- # set are not valid +Mongo::DBs+, then an error will be raise.
81
+ # Sets the Mongo::DB slave databases to be used. If the objects provided
82
+ # are not valid +Mongo::DBs+ an error will be raised.
83
83
  #
84
84
  # Example:
85
85
  #
@@ -87,8 +87,9 @@ module Mongoid #:nodoc
87
87
  #
88
88
  # Returns:
89
89
  #
90
- # The slaves DB instances.
90
+ # The slave DB instances.
91
91
  def slaves=(dbs)
92
+ return unless dbs
92
93
  dbs.each do |db|
93
94
  check_database!(db)
94
95
  end
@@ -164,10 +165,7 @@ module Mongoid #:nodoc
164
165
  #
165
166
  # <tt>config._master({}, "test")</tt>
166
167
  def _master(settings)
167
- name = settings["database"]
168
- host = settings.delete("host") || "localhost"
169
- port = settings.delete("port") || 27017
170
- self.master = Mongo::Connection.new(host, port, :logger => logger).db(name)
168
+ self.master = database_from_hash(settings)
171
169
  end
172
170
 
173
171
  # Get a bunch-o-slaves from settings and names.
@@ -176,16 +174,32 @@ module Mongoid #:nodoc
176
174
  #
177
175
  # <tt>config._slaves({}, "test")</tt>
178
176
  def _slaves(settings)
179
- name = settings["database"]
180
- self.slaves = []
181
- slaves = settings.delete("slaves")
182
- slaves.to_a.each do |slave|
183
- self.slaves << Mongo::Connection.new(
184
- slave["host"],
185
- slave["port"],
186
- :slave_ok => true
187
- ).db(name)
177
+ self.slaves = settings["slaves"].to_a.map do |slave|
178
+ database_from_hash({"database" => master.name}.merge(slave), :slave_ok => true)
188
179
  end
189
180
  end
181
+
182
+ def database_from_hash(settings, connection_options={})
183
+ mongo_uri = settings["uri"].present? ? URI.parse(settings["uri"]) : OpenStruct.new
184
+
185
+ name = settings["database"] || mongo_uri.path.to_s.sub("/", "")
186
+ host = settings["host"] || mongo_uri.host || "localhost"
187
+ port = settings["port"] || mongo_uri.port || 27017
188
+ pool_size = settings["pool_size"] || 1
189
+ username = settings["username"] || mongo_uri.user
190
+ password = settings["password"] || mongo_uri.password
191
+
192
+ local_options = {
193
+ :logger => logger,
194
+ :pool_size => pool_size
195
+ }.merge(connection_options)
196
+
197
+ Mongo::Connection.new(host, port, local_options).tap do |connection|
198
+ if username || password
199
+ connection.add_auth(name, username, password)
200
+ connection.apply_saved_authentication
201
+ end
202
+ end.db(name)
203
+ end
190
204
  end
191
205
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "1.9.2"
3
+ VERSION = "1.9.5"
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 57
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 9
9
- - 2
10
- version: 1.9.2
9
+ - 5
10
+ version: 1.9.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Durran Jordan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-17 00:00:00 -04:00
18
+ date: 2011-02-14 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -73,12 +73,12 @@ dependencies:
73
73
  requirements:
74
74
  - - ~>
75
75
  - !ruby/object:Gem::Version
76
- hash: 21
76
+ hash: 29
77
77
  segments:
78
78
  - 1
79
- - 0
79
+ - 2
80
80
  - 1
81
- version: 1.0.1
81
+ version: 1.2.1
82
82
  type: :runtime
83
83
  version_requirements: *id004
84
84
  - !ruby/object:Gem::Dependency
@@ -89,12 +89,12 @@ dependencies:
89
89
  requirements:
90
90
  - - ~>
91
91
  - !ruby/object:Gem::Version
92
- hash: 21
92
+ hash: 29
93
93
  segments:
94
94
  - 1
95
- - 0
95
+ - 2
96
96
  - 1
97
- version: 1.0.1
97
+ version: 1.2.1
98
98
  type: :runtime
99
99
  version_requirements: *id005
100
100
  - !ruby/object:Gem::Dependency