mongoid 3.0.10 → 3.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +14 -0
- data/lib/mongoid/atomic.rb +17 -0
- data/lib/mongoid/config.rb +12 -0
- data/lib/mongoid/criteria.rb +21 -0
- data/lib/mongoid/railtie.rb +25 -1
- data/lib/mongoid/relations/embedded/one.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/rack/mongoid/middleware/identity_map.rb +32 -0
- metadata +3 -3
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,20 @@
|
|
3
3
|
For instructions on upgrading to newer versions, visit
|
4
4
|
[mongoid.org](http://mongoid.org/docs/upgrading.html).
|
5
5
|
|
6
|
+
## 3.0.11
|
7
|
+
|
8
|
+
### Resolved Issues
|
9
|
+
|
10
|
+
* \#2522 Fixed `Criteria#with` to return the criteria and not the class.
|
11
|
+
|
12
|
+
* \#2518 Fix unit of work call for the identity map when using Passenger.
|
13
|
+
|
14
|
+
* \#2512 Ensure nested attributes destroy works with the delayed destroys
|
15
|
+
introduced in 3.0.10 when multiple levels deep.
|
16
|
+
|
17
|
+
* \#2509 Don't hit identity map an extra time when the returned value is an
|
18
|
+
empty hash. (Douwe Maan)
|
19
|
+
|
6
20
|
## 3.0.10
|
7
21
|
|
8
22
|
### Resolved Issues
|
data/lib/mongoid/atomic.rb
CHANGED
@@ -118,6 +118,7 @@ module Mongoid
|
|
118
118
|
mods = Modifiers.new
|
119
119
|
generate_atomic_updates(mods, self)
|
120
120
|
_children.each do |child|
|
121
|
+
child.process_flagged_destroys
|
121
122
|
generate_atomic_updates(mods, child)
|
122
123
|
end
|
123
124
|
mods
|
@@ -303,10 +304,26 @@ module Mongoid
|
|
303
304
|
atomic_path
|
304
305
|
end
|
305
306
|
|
307
|
+
# Get the flagged destroys.
|
308
|
+
#
|
309
|
+
# @example Get the flagged destroy.
|
310
|
+
# document.flagged_destroys
|
311
|
+
#
|
312
|
+
# @return [ Array<Proc> ] The flagged destroys.
|
313
|
+
#
|
314
|
+
# @since 3.0.10
|
306
315
|
def flagged_destroys
|
307
316
|
@flagged_destroys ||= []
|
308
317
|
end
|
309
318
|
|
319
|
+
# Process all the pending flagged destroys from nested attributes.
|
320
|
+
#
|
321
|
+
# @example Process all the pending flagged destroys.
|
322
|
+
# document.process_flagged_destroys
|
323
|
+
#
|
324
|
+
# @return [ Array ] The cleared array.
|
325
|
+
#
|
326
|
+
# @since 3.0.10
|
310
327
|
def process_flagged_destroys
|
311
328
|
_assigning do
|
312
329
|
flagged_destroys.each do |block|
|
data/lib/mongoid/config.rb
CHANGED
@@ -145,6 +145,18 @@ module Mongoid
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
+
# Is the application running under passenger?
|
149
|
+
#
|
150
|
+
# @example Is the application using passenger?
|
151
|
+
# config.running_with_passenger?
|
152
|
+
#
|
153
|
+
# @return [ true, false ] If the app is deployed on Passenger.
|
154
|
+
#
|
155
|
+
# @since 3.0.11
|
156
|
+
def running_with_passenger?
|
157
|
+
@running_with_passenger ||= defined?(PhusionPassenger)
|
158
|
+
end
|
159
|
+
|
148
160
|
# Get the session configuration or an empty hash.
|
149
161
|
#
|
150
162
|
# @example Get the sessions configuration.
|
data/lib/mongoid/criteria.rb
CHANGED
@@ -291,6 +291,7 @@ module Mongoid
|
|
291
291
|
id = extract_id
|
292
292
|
id = klass.fields["_id"].mongoize(id) if id
|
293
293
|
doc = IdentityMap.get(klass, id || selector.except("_type"))
|
294
|
+
return nil if doc == {}
|
294
295
|
doc && doc.matches?(selector) ? doc : first
|
295
296
|
end
|
296
297
|
|
@@ -526,6 +527,26 @@ module Mongoid
|
|
526
527
|
super
|
527
528
|
end
|
528
529
|
|
530
|
+
# Tell the next persistance operation to query from a specific collection,
|
531
|
+
# database or session.
|
532
|
+
#
|
533
|
+
# @example Send the criteria to another collection.
|
534
|
+
# Band.where(name: "Depeche Mode").with(collection: "artists")
|
535
|
+
#
|
536
|
+
# @param [ Hash ] options The storage options.
|
537
|
+
#
|
538
|
+
# @option options [ String, Symbol ] :collection The collection name.
|
539
|
+
# @option options [ String, Symbol ] :database The database name.
|
540
|
+
# @option options [ String, Symbol ] :session The session name.
|
541
|
+
#
|
542
|
+
# @return [ Criteria ] The criteria.
|
543
|
+
#
|
544
|
+
# @since 3.0.0
|
545
|
+
def with(options)
|
546
|
+
Threaded.set_persistence_options(klass, options)
|
547
|
+
self
|
548
|
+
end
|
549
|
+
|
529
550
|
# Get a version of this criteria without the options.
|
530
551
|
#
|
531
552
|
# @example Get the criteria without options.
|
data/lib/mongoid/railtie.rb
CHANGED
@@ -118,7 +118,11 @@ module Rails
|
|
118
118
|
|
119
119
|
# Need to include the Mongoid identity map middleware.
|
120
120
|
initializer "include the identity map" do |app|
|
121
|
-
|
121
|
+
if ::Mongoid.running_with_passenger?
|
122
|
+
app.config.middleware.use "Rack::Mongoid::Middleware::IdentityMap::Passenger"
|
123
|
+
else
|
124
|
+
app.config.middleware.use "Rack::Mongoid::Middleware::IdentityMap"
|
125
|
+
end
|
122
126
|
end
|
123
127
|
|
124
128
|
# Instantitate any registered observers after Rails initialization and
|
@@ -132,6 +136,26 @@ module Rails
|
|
132
136
|
end
|
133
137
|
end
|
134
138
|
|
139
|
+
initializer "reconnect to master if application is preloaded" do
|
140
|
+
config.after_initialize do
|
141
|
+
# Unicorn clears the START_CTX when a worker is forked, so if we have
|
142
|
+
# data in START_CTX then we know we're being preloaded. Unicorn does
|
143
|
+
# not provide application-level hooks for executing code after the
|
144
|
+
# process has forked, so we reconnect lazily.
|
145
|
+
if defined?(Unicorn) && !Unicorn::HttpServer::START_CTX.empty?
|
146
|
+
::Mongoid.default_session.disconnect
|
147
|
+
end
|
148
|
+
|
149
|
+
# Passenger provides the :starting_worker_process event for executing
|
150
|
+
# code after it has forked, so we use that and reconnect immediately.
|
151
|
+
if ::Mongoid.running_with_passenger?
|
152
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
153
|
+
::Mongoid.default_session.disconnect if forked
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
135
159
|
# Rails runs all initializers first before getting into any generator
|
136
160
|
# code, so we have no way in the intitializer to know if we are
|
137
161
|
# generating a mongoid.yml. So instead of failing, we catch all the
|
data/lib/mongoid/version.rb
CHANGED
@@ -37,6 +37,38 @@ module Rack
|
|
37
37
|
end
|
38
38
|
response
|
39
39
|
end
|
40
|
+
|
41
|
+
# Passenger 3 does not execute the block provided to a Rack::BodyProxy
|
42
|
+
# so the identity map never gets cleared. Since there's no streaming
|
43
|
+
# support in it anyways we do not need the proxy functionality.
|
44
|
+
class Passenger
|
45
|
+
|
46
|
+
# Initialize the new middleware.
|
47
|
+
#
|
48
|
+
# @example Init the middleware.
|
49
|
+
# IdentityMap.new(app)
|
50
|
+
#
|
51
|
+
# @param [ Object ] app The application.
|
52
|
+
#
|
53
|
+
# @since 3.0.11
|
54
|
+
def initialize(app)
|
55
|
+
@app = app
|
56
|
+
end
|
57
|
+
|
58
|
+
# Make the request with the provided environment.
|
59
|
+
#
|
60
|
+
# @example Make the request.
|
61
|
+
# identity_map.call(env)
|
62
|
+
#
|
63
|
+
# @param [ Object ] env The environment.
|
64
|
+
#
|
65
|
+
# @return [ Array ] The status, headers, and response.
|
66
|
+
#
|
67
|
+
# @since 3.0.11
|
68
|
+
def call(env)
|
69
|
+
::Mongoid.unit_of_work { @app.call(env) }
|
70
|
+
end
|
71
|
+
end
|
40
72
|
end
|
41
73
|
end
|
42
74
|
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: 3.0.
|
4
|
+
version: 3.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -352,7 +352,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
352
352
|
version: '0'
|
353
353
|
segments:
|
354
354
|
- 0
|
355
|
-
hash:
|
355
|
+
hash: 1182744462779695789
|
356
356
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
357
357
|
none: false
|
358
358
|
requirements:
|