mongoid 2.4.2 → 2.4.3
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.
- data/CHANGELOG.md +22 -1
- data/lib/mongoid/collection.rb +1 -1
- data/lib/mongoid/contexts/enumerable.rb +24 -0
- data/lib/mongoid/copyable.rb +6 -7
- data/lib/mongoid/fields/internal/date_time.rb +1 -1
- data/lib/mongoid/fields/internal/timekeeping.rb +2 -1
- data/lib/mongoid/matchers/all.rb +8 -1
- data/lib/mongoid/matchers/in.rb +8 -1
- data/lib/mongoid/named_scope.rb +15 -0
- data/lib/mongoid/observer.rb +7 -0
- data/lib/mongoid/railtie.rb +21 -8
- data/lib/mongoid/relations/embedded/atomic.rb +3 -3
- data/lib/mongoid/relations/proxy.rb +1 -0
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/versioning.rb +1 -1
- metadata +21 -21
data/CHANGELOG.md
CHANGED
@@ -3,7 +3,28 @@
|
|
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.
|
6
|
+
## 2.4.3 \[ In Development \] \[ Branch: 2.4.0-stable \]
|
7
|
+
|
8
|
+
### Resolved Issues
|
9
|
+
|
10
|
+
* \#1647 DateTime serialization when already in UTC does not convert to
|
11
|
+
local time.
|
12
|
+
|
13
|
+
* \#1640 Update consumers should be tied to the name of the collection
|
14
|
+
they persist to, not the name of the class.
|
15
|
+
|
16
|
+
* \#1636 Scopes no longer modify parent class scopes when subclassing.
|
17
|
+
(Hans Hasselberg)
|
18
|
+
|
19
|
+
* \#1629 $all and $in criteria on embedded many relations now properly
|
20
|
+
handles regex searches and elements of varying length. (Douwe Maan)
|
21
|
+
|
22
|
+
* \#1623 Default scopes no longer break Mongoid::Versioning.
|
23
|
+
(Hans Hasselberg)
|
24
|
+
|
25
|
+
* \#1605 Fix regression of rescue responses, Rails 3.2
|
26
|
+
|
27
|
+
## 2.4.2
|
7
28
|
|
8
29
|
### Resolved Issues
|
9
30
|
|
data/lib/mongoid/collection.rb
CHANGED
@@ -142,7 +142,7 @@ module Mongoid #:nodoc
|
|
142
142
|
#
|
143
143
|
# @since 2.0.0
|
144
144
|
def update(selector, document, options = {})
|
145
|
-
updater = Threaded.update_consumer(
|
145
|
+
updater = Threaded.update_consumer(name)
|
146
146
|
if updater
|
147
147
|
updater.consume(selector, document, options)
|
148
148
|
else
|
@@ -210,6 +210,18 @@ module Mongoid #:nodoc:
|
|
210
210
|
|
211
211
|
protected
|
212
212
|
|
213
|
+
# Get the root class collection name.
|
214
|
+
#
|
215
|
+
# @example Get the root class collection name.
|
216
|
+
# context.collection_name
|
217
|
+
#
|
218
|
+
# @return [ String ] The name of the collection.
|
219
|
+
#
|
220
|
+
# @since 2.4.3
|
221
|
+
def collection_name
|
222
|
+
root ? root.collection_name : nil
|
223
|
+
end
|
224
|
+
|
213
225
|
# Filters the documents against the criteria's selector
|
214
226
|
#
|
215
227
|
# @example Filter the documents.
|
@@ -251,10 +263,22 @@ module Mongoid #:nodoc:
|
|
251
263
|
documents
|
252
264
|
end
|
253
265
|
|
266
|
+
# Get the root document for the enumerable.
|
267
|
+
#
|
268
|
+
# @example Get the root document.
|
269
|
+
# context.root
|
270
|
+
#
|
271
|
+
# @return [ Document ] The root.
|
254
272
|
def root
|
255
273
|
@root ||= documents.first.try(:_root)
|
256
274
|
end
|
257
275
|
|
276
|
+
# Get the root class for the enumerable.
|
277
|
+
#
|
278
|
+
# @example Get the root class.
|
279
|
+
# context.root_class
|
280
|
+
#
|
281
|
+
# @return [ Class ] The root class.
|
258
282
|
def root_class
|
259
283
|
@root_class ||= root ? root.class : nil
|
260
284
|
end
|
data/lib/mongoid/copyable.rb
CHANGED
@@ -6,11 +6,10 @@ module Mongoid #:nodoc:
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
COPYABLES = [
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
:@previous_modifications
|
9
|
+
:attributes,
|
10
|
+
:metadata,
|
11
|
+
:changed_attributes,
|
12
|
+
:previous_changes
|
14
13
|
]
|
15
14
|
|
16
15
|
protected
|
@@ -34,8 +33,8 @@ module Mongoid #:nodoc:
|
|
34
33
|
other.as_document
|
35
34
|
instance_variables.each { |name| remove_instance_variable(name) }
|
36
35
|
COPYABLES.each do |name|
|
37
|
-
value = other.
|
38
|
-
instance_variable_set(name, value ? value.dup : nil)
|
36
|
+
value = other.send(name)
|
37
|
+
instance_variable_set(:"@#{name}", value ? value.dup : nil)
|
39
38
|
end
|
40
39
|
attributes.delete("_id")
|
41
40
|
if attributes.delete("versions")
|
@@ -32,7 +32,7 @@ module Mongoid #:nodoc:
|
|
32
32
|
return nil if object.blank?
|
33
33
|
object = object.getlocal unless Mongoid::Config.use_utc?
|
34
34
|
if Mongoid::Config.use_activesupport_time_zone?
|
35
|
-
time_zone = Mongoid::Config.use_utc? ?
|
35
|
+
time_zone = Mongoid::Config.use_utc? ? "UTC" : ::Time.zone
|
36
36
|
object = object.in_time_zone(time_zone)
|
37
37
|
end
|
38
38
|
object
|
@@ -90,6 +90,7 @@ module Mongoid #:nodoc:
|
|
90
90
|
when ::String
|
91
91
|
time.parse(value)
|
92
92
|
when ::DateTime
|
93
|
+
return value if value.utc? && Mongoid.use_utc?
|
93
94
|
time.local(value.year, value.month, value.day, value.hour, value.min, value.sec)
|
94
95
|
when ::Date
|
95
96
|
time.local(value.year, value.month, value.day)
|
data/lib/mongoid/matchers/all.rb
CHANGED
@@ -14,7 +14,14 @@ module Mongoid #:nodoc:
|
|
14
14
|
#
|
15
15
|
# @return [ true, false ] If the values match.
|
16
16
|
def matches?(value)
|
17
|
-
|
17
|
+
attribute_array = Array.wrap(@attribute)
|
18
|
+
value.values.first.all? do |e|
|
19
|
+
if e.is_a?(Regexp)
|
20
|
+
attribute_array.any? { |_attribute| _attribute =~ e }
|
21
|
+
else
|
22
|
+
attribute_array.include?(e)
|
23
|
+
end
|
24
|
+
end
|
18
25
|
end
|
19
26
|
end
|
20
27
|
end
|
data/lib/mongoid/matchers/in.rb
CHANGED
@@ -14,7 +14,14 @@ module Mongoid #:nodoc:
|
|
14
14
|
#
|
15
15
|
# @return [ true, false ] If a value exists.
|
16
16
|
def matches?(value)
|
17
|
-
Array.wrap(@attribute)
|
17
|
+
attribute_array = Array.wrap(@attribute)
|
18
|
+
value.values.first.any? do |e|
|
19
|
+
if e.is_a?(Regexp)
|
20
|
+
attribute_array.any? { |_attribute| _attribute =~ e }
|
21
|
+
else
|
22
|
+
attribute_array.include?(e)
|
23
|
+
end
|
24
|
+
end
|
18
25
|
end
|
19
26
|
end
|
20
27
|
end
|
data/lib/mongoid/named_scope.rb
CHANGED
@@ -123,6 +123,21 @@ module Mongoid #:nodoc:
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
# When inheriting, we want to copy the scopes from the parent class and
|
127
|
+
# set the on the child to start, mimicking the behaviour of the old
|
128
|
+
# class_inheritable_accessor that was deprecated in Rails edge.
|
129
|
+
#
|
130
|
+
# @example Inherit from this class.
|
131
|
+
# Person.inherited(Doctor)
|
132
|
+
#
|
133
|
+
# @param [ Class ] subclass The inheriting class.
|
134
|
+
#
|
135
|
+
# @since 2.0.0.rc.6
|
136
|
+
def inherited(subclass)
|
137
|
+
super
|
138
|
+
subclass.scopes = scopes.dup
|
139
|
+
end
|
140
|
+
|
126
141
|
protected
|
127
142
|
|
128
143
|
# Warns or raises exception if overriding another scope or method.
|
data/lib/mongoid/observer.rb
CHANGED
@@ -170,5 +170,12 @@ module Mongoid #:nodoc:
|
|
170
170
|
end
|
171
171
|
end
|
172
172
|
end
|
173
|
+
|
174
|
+
def disabled_for?(object)
|
175
|
+
klass = object.class
|
176
|
+
return false unless klass.respond_to?(:observers)
|
177
|
+
klass.observers.disabled_for?(self) || Mongoid.observers.disabled_for?(self)
|
178
|
+
end
|
179
|
+
|
173
180
|
end
|
174
181
|
end
|
data/lib/mongoid/railtie.rb
CHANGED
@@ -23,8 +23,27 @@ module Rails #:nodoc:
|
|
23
23
|
config.respond_to?(:app_generators) ? :app_generators : :generators
|
24
24
|
end
|
25
25
|
|
26
|
+
# Maping of rescued exceptions to HTTP responses
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# railtie.rescue_responses
|
30
|
+
#
|
31
|
+
# @ return [Hash] rescued responses
|
32
|
+
#
|
33
|
+
# @since 2.4.3
|
34
|
+
def self.rescue_responses
|
35
|
+
{
|
36
|
+
"Mongoid::Errors::DocumentNotFound" => :not_found,
|
37
|
+
"Mongoid::Errors::Validations" => 422
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
26
41
|
config.send(generator).orm :mongoid, :migration => false
|
27
42
|
|
43
|
+
if config.action_dispatch.rescue_responses
|
44
|
+
config.action_dispatch.rescue_responses.merge!(rescue_responses)
|
45
|
+
end
|
46
|
+
|
28
47
|
rake_tasks do
|
29
48
|
load "mongoid/railties/database.rake"
|
30
49
|
end
|
@@ -81,14 +100,8 @@ module Rails #:nodoc:
|
|
81
100
|
# 404s and not 500s, validation errors are 422s.
|
82
101
|
initializer "load http errors" do |app|
|
83
102
|
config.after_initialize do
|
84
|
-
|
85
|
-
|
86
|
-
"Mongoid::Errors::Validations" => 422
|
87
|
-
}
|
88
|
-
if rescue_responses = config.action_dispatch.rescue_responses
|
89
|
-
rescue_responses.update(responses)
|
90
|
-
else
|
91
|
-
ActionDispatch::ShowExceptions.rescue_responses.update(responses)
|
103
|
+
unless config.action_dispatch.rescue_responses
|
104
|
+
ActionDispatch::ShowExceptions.rescue_responses.update(Railtie.rescue_responses)
|
92
105
|
end
|
93
106
|
end
|
94
107
|
end
|
@@ -55,13 +55,13 @@ module Mongoid #:nodoc:
|
|
55
55
|
#
|
56
56
|
# @since 2.0.0
|
57
57
|
def atomically(modifier, &block)
|
58
|
-
updater = Threaded.update_consumer(
|
59
|
-
Threaded.set_update_consumer(
|
58
|
+
updater = Threaded.update_consumer(collection_name) ||
|
59
|
+
Threaded.set_update_consumer(collection_name, MODIFIERS[modifier].new)
|
60
60
|
count_executions do
|
61
61
|
block.call if block
|
62
62
|
end.tap do
|
63
63
|
if @executions.zero?
|
64
|
-
Threaded.set_update_consumer(
|
64
|
+
Threaded.set_update_consumer(collection_name, nil)
|
65
65
|
updater.execute(collection)
|
66
66
|
end
|
67
67
|
end
|
@@ -18,6 +18,7 @@ module Mongoid # :nodoc:
|
|
18
18
|
# Backwards compatibility with Mongoid beta releases.
|
19
19
|
delegate :klass, :to => :metadata
|
20
20
|
delegate :bind_one, :unbind_one, :to => :binding
|
21
|
+
delegate :collection_name, :to => :base
|
21
22
|
|
22
23
|
# Convenience for setting the target and the metadata properties since
|
23
24
|
# all proxies will need to do this.
|
data/lib/mongoid/version.rb
CHANGED
data/lib/mongoid/versioning.rb
CHANGED
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.
|
4
|
+
version: 2.4.3
|
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-01-
|
12
|
+
date: 2012-01-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
16
|
-
requirement: &
|
16
|
+
requirement: &70324286112920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70324286112920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: tzinfo
|
27
|
-
requirement: &
|
27
|
+
requirement: &70324286112300 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.3.22
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70324286112300
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: mongo
|
38
|
-
requirement: &
|
38
|
+
requirement: &70324286111520 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '1.3'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70324286111520
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &70324286110820 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 3.5.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70324286110820
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bson_ext
|
60
|
-
requirement: &
|
60
|
+
requirement: &70324286066060 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '1.3'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70324286066060
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: mocha
|
71
|
-
requirement: &
|
71
|
+
requirement: &70324286064560 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0.10'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70324286064560
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rspec
|
82
|
-
requirement: &
|
82
|
+
requirement: &70324286063860 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '2.6'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70324286063860
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: guard-rspec
|
93
|
-
requirement: &
|
93
|
+
requirement: &70324286063360 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0.6'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70324286063360
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: ammeter
|
104
|
-
requirement: &
|
104
|
+
requirement: &70324286062880 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: 0.1.3
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70324286062880
|
113
113
|
description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
|
114
114
|
in Ruby.
|
115
115
|
email:
|
@@ -414,7 +414,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
414
414
|
version: '0'
|
415
415
|
segments:
|
416
416
|
- 0
|
417
|
-
hash:
|
417
|
+
hash: 907876578455724233
|
418
418
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
419
419
|
none: false
|
420
420
|
requirements:
|