mongoid 2.4.6 → 2.4.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,27 @@
3
3
  For instructions on upgrading to newer versions, visit
4
4
  [mongoid.org](http://mongoid.org/docs/upgrading.html).
5
5
 
6
+ ## 2.4.7
7
+
8
+ ### Resolved Issues
9
+
10
+ * Ensure reloading of embedded documents retains reference to the parent.
11
+
12
+ * \#1837 Always pass symbol options to the driver.
13
+
14
+ * \#1836 Ensure relation counts pick up persisted document that have not
15
+ had the foreign key link persisted.
16
+
17
+ * \#1820 Destroying embedded documents in an embeds_many should also
18
+ removed the document from the underlying _uncoped target and reindex
19
+ the relation.
20
+
21
+ * \#1814 Don't cascade callbacks on after_initialize.
22
+
23
+ * \#1800 Invalid options for the Mongo connection are now filtered out.
24
+
25
+ * \#1785 Case equality has been fixed to handle instance checks properly.
26
+
6
27
  ## 2.4.6
7
28
 
8
29
  ### Resolved Issues
@@ -105,7 +105,8 @@ module Mongoid #:nodoc:
105
105
  #
106
106
  # @since 2.3.0
107
107
  def cascadable_child?(kind, child)
108
- [ :create, :destroy, :initialize ].include?(kind) || child.changed? || child.new_record?
108
+ return false if kind == :initialize
109
+ [ :create, :destroy ].include?(kind) || child.changed? || child.new_record?
109
110
  end
110
111
 
111
112
  # Get the name of the callback that the child should fire. This changes
@@ -53,6 +53,21 @@ module Mongoid #:nodoc
53
53
  end
54
54
  end
55
55
 
56
+ # keys to remove from self to not pass through to Mongo::Connection
57
+ PRIVATE_OPTIONS = %w(uri host hosts port database databases username password logger)
58
+
59
+ # Get the blacklisted options from passing through to the driver.
60
+ #
61
+ # @example Get the blacklisted options.
62
+ # Config.blacklisted_options
63
+ #
64
+ # @return [ Array<String> ] The blacklist.
65
+ #
66
+ # @since 2.4.7
67
+ def blacklisted_options
68
+ PRIVATE_OPTIONS + settings.keys.map(&:to_s)
69
+ end
70
+
56
71
  # Get any extra databases that have been configured.
57
72
  #
58
73
  # @example Get the extras.
@@ -6,9 +6,6 @@ module Mongoid #:nodoc:
6
6
  # database from options.
7
7
  class Database < Hash
8
8
 
9
- # keys to remove from self to not pass through to Mongo::Connection
10
- PRIVATE_OPTIONS = %w(uri database username password logger)
11
-
12
9
  # Configure the database connections. This will return an array
13
10
  # containing the master and an array of slaves.
14
11
  #
@@ -86,7 +83,7 @@ module Mongoid #:nodoc:
86
83
  #
87
84
  # @since 2.0.0.rc.1
88
85
  def master
89
- Mongo::Connection.from_uri(uri(self), optional).tap do |conn|
86
+ Mongo::Connection.from_uri(uri(self), optional.symbolize_keys).tap do |conn|
90
87
  conn.apply_saved_authentication
91
88
  end
92
89
  end
@@ -102,7 +99,7 @@ module Mongoid #:nodoc:
102
99
  # @since 2.0.0.rc.1
103
100
  def slaves
104
101
  (self["slaves"] || []).map do |options|
105
- Mongo::Connection.from_uri(uri(options), optional(true)).tap do |conn|
102
+ Mongo::Connection.from_uri(uri(options), optional(true).symbolize_keys).tap do |conn|
106
103
  conn.apply_saved_authentication
107
104
  end
108
105
  end
@@ -162,8 +159,8 @@ module Mongoid #:nodoc:
162
159
  :pool_size => pool_size,
163
160
  :logger => logger? ? Mongoid::Logger.new : nil,
164
161
  :slave_ok => slave
165
- }).merge(self).reject { |k,v| PRIVATE_OPTIONS.include? k }.
166
- inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo} # mongo likes symbols
162
+ }).merge(self).reject { |k,v| Config.blacklisted_options.include? k }.
163
+ inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo}
167
164
  end
168
165
 
169
166
  # Get a Mongo compliant URI for the database connection.
@@ -17,11 +17,9 @@ module Mongoid #:nodoc:
17
17
  # yes, construction is weird but the driver wants
18
18
  # "A list of host-port pairs ending with a hash containing any options"
19
19
  # mongo likes symbols
20
- options = self.inject({ :logger => Mongoid::Logger.new }) do |memo, (k, v)|
21
- memo[k.to_sym] = v
22
- memo
23
- end
24
- connection = Mongo::ReplSetConnection.new(*(hosts.clone << options))
20
+ options = reject{ |key, value| Config.blacklisted_options.include?(key.to_s) }
21
+ options["logger"] = Mongoid::Logger.new
22
+ connection = Mongo::ReplSetConnection.new(*(hosts.clone << options.symbolize_keys))
25
23
 
26
24
  if authenticating?
27
25
  connection.add_auth(database, username, password)
@@ -44,7 +44,11 @@ module Mongoid #:nodoc:
44
44
  #
45
45
  # @return [ true, false ] True if the classes are equal, false if not.
46
46
  def ===(other)
47
- other.is_a?(self.class)
47
+ if other.class == Class
48
+ self.class === other
49
+ else
50
+ id == other.id
51
+ end
48
52
  end
49
53
 
50
54
  # Delegates to ==. Used when needing checks in hashes.
@@ -276,7 +280,7 @@ module Mongoid #:nodoc:
276
280
  #
277
281
  # @since 2.0.0.rc.4
278
282
  def ===(other)
279
- other.is_a?(Class) ? self == other : other.is_a?(self)
283
+ other.class == Class ? self <= other : other.is_a?(self)
280
284
  end
281
285
 
282
286
  # Instantiate a new object, only when loaded from the database or when
@@ -69,7 +69,12 @@ module Mongoid #:nodoc
69
69
  # @since 2.0.0.beta.1
70
70
  def remove_child(child)
71
71
  name = child.metadata.name
72
- child.embedded_one? ? remove_ivar(name) : send(name).delete_one(child)
72
+ if child.embedded_one?
73
+ remove_ivar(name)
74
+ else
75
+ relation = send(name)
76
+ relation.send(:delete_one, child)
77
+ end
73
78
  end
74
79
 
75
80
  # After children are persisted we can call this to move all their changes
@@ -119,7 +119,9 @@ module Mongoid # :nodoc:
119
119
  def reload_relations
120
120
  relations.each_pair do |name, meta|
121
121
  if instance_variable_defined?("@#{name}")
122
- remove_instance_variable("@#{name}")
122
+ if _parent.nil? || instance_variable_get("@#{name}") != _parent
123
+ remove_instance_variable("@#{name}")
124
+ end
123
125
  end
124
126
  end
125
127
  end
@@ -28,6 +28,22 @@ module Mongoid # :nodoc:
28
28
  end
29
29
  alias :push :<<
30
30
 
31
+ # Get this relation as as its representation in the database.
32
+ #
33
+ # @example Convert the relation to an attributes hash.
34
+ # person.addresses.as_document
35
+ #
36
+ # @return [ Array<Hash> ] The relation as stored in the db.
37
+ #
38
+ # @since 2.0.0.rc.1
39
+ def as_document
40
+ [].tap do |attributes|
41
+ _unscoped.each do |doc|
42
+ attributes.push(doc.as_document)
43
+ end
44
+ end
45
+ end
46
+
31
47
  # Appends an array of documents to the relation. Performs a batch
32
48
  # insert of the documents instead of persisting one at a time.
33
49
  #
@@ -308,22 +324,6 @@ module Mongoid # :nodoc:
308
324
  end
309
325
  end
310
326
 
311
- # Get this relation as as its representation in the database.
312
- #
313
- # @example Convert the relation to an attributes hash.
314
- # person.addresses.as_document
315
- #
316
- # @return [ Array<Hash> ] The relation as stored in the db.
317
- #
318
- # @since 2.0.0.rc.1
319
- def as_document
320
- [].tap do |attributes|
321
- _unscoped.each do |doc|
322
- attributes.push(doc.as_document)
323
- end
324
- end
325
- end
326
-
327
327
  # Return the relation with all previous scoping removed. This is the
328
328
  # exact representation of the docs in the database.
329
329
  #
@@ -384,6 +384,22 @@ module Mongoid # :nodoc:
384
384
  end
385
385
  end
386
386
 
387
+ # Deletes one document from the target and unscoped.
388
+ #
389
+ # @api private
390
+ #
391
+ # @example Delete one document.
392
+ # relation.delete_one(doc)
393
+ #
394
+ # @param [ Document ] document The document to delete.
395
+ #
396
+ # @since 2.4.7
397
+ def delete_one(document)
398
+ target.delete_one(document)
399
+ _unscoped.delete_one(document)
400
+ reindex
401
+ end
402
+
387
403
  # Integrate the document into the relation. will set its metadata and
388
404
  # attempt to bind the inverse.
389
405
  #
@@ -316,7 +316,12 @@ module Mongoid #:nodoc:
316
316
  #
317
317
  # @since 2.1.0
318
318
  def size
319
- (unloaded ? unloaded.count : loaded.count) + added.count{ |d| d.new? }
319
+ count = (unloaded ? unloaded.count : loaded.count)
320
+ if count.zero?
321
+ count + added.count
322
+ else
323
+ count + added.count{ |d| d.new_record? }
324
+ end
320
325
  end
321
326
  alias :length :size
322
327
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.4.6"
3
+ VERSION = "2.4.7"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.6
4
+ version: 2.4.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-05 00:00:00.000000000 Z
12
+ date: 2012-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
16
- requirement: &70290122566500 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70290122566500
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: tzinfo
27
- requirement: &70290122563300 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 0.3.22
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70290122563300
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.3.22
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: mongo
38
- requirement: &70290122575540 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '1.3'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70290122575540
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rdoc
49
- requirement: &70290122572600 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: 3.5.0
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70290122572600
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 3.5.0
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: bson_ext
60
- requirement: &70290122570780 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ~>
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '1.3'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70290122570780
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '1.3'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: mocha
71
- requirement: &70290122594580 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ~>
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '0.10'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70290122594580
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '0.10'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: rspec
82
- requirement: &70290122606300 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ~>
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: '2.6'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *70290122606300
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '2.6'
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: guard-rspec
93
- requirement: &70290122604280 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ~>
@@ -98,10 +133,15 @@ dependencies:
98
133
  version: '0.6'
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *70290122604280
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: '0.6'
102
142
  - !ruby/object:Gem::Dependency
103
143
  name: ammeter
104
- requirement: &70290122602380 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
105
145
  none: false
106
146
  requirements:
107
147
  - - ~>
@@ -109,7 +149,12 @@ dependencies:
109
149
  version: 0.1.3
110
150
  type: :development
111
151
  prerelease: false
112
- version_requirements: *70290122602380
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 0.1.3
113
158
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
114
159
  in Ruby.
115
160
  email:
@@ -414,7 +459,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
414
459
  version: '0'
415
460
  segments:
416
461
  - 0
417
- hash: 2263773657060838243
462
+ hash: -4230484003984922722
418
463
  required_rubygems_version: !ruby/object:Gem::Requirement
419
464
  none: false
420
465
  requirements:
@@ -423,7 +468,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
423
468
  version: 1.3.6
424
469
  requirements: []
425
470
  rubyforge_project: mongoid
426
- rubygems_version: 1.8.10
471
+ rubygems_version: 1.8.19
427
472
  signing_key:
428
473
  specification_version: 3
429
474
  summary: Elegant Persistance in Ruby for MongoDB.