mongoid 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +57 -3
- data/Rakefile +1 -1
- data/lib/mongoid/atomic/modifiers.rb +2 -1
- data/lib/mongoid/config.rb +0 -1
- data/lib/mongoid/config/replset_database.rb +2 -2
- data/lib/mongoid/contexts/mongo.rb +14 -5
- data/lib/mongoid/criteria.rb +4 -4
- data/lib/mongoid/criterion/inclusion.rb +16 -1
- data/lib/mongoid/document.rb +2 -4
- data/lib/mongoid/extensions.rb +7 -0
- data/lib/mongoid/extensions/integer/checks.rb +23 -0
- data/lib/mongoid/extensions/object/yoda.rb +16 -0
- data/lib/mongoid/extensions/object_id/conversions.rb +1 -1
- data/lib/mongoid/extensions/string/checks.rb +24 -0
- data/lib/mongoid/extensions/string/inflections.rb +1 -1
- data/lib/mongoid/fields.rb +4 -2
- data/lib/mongoid/fields/serializable.rb +26 -18
- data/lib/mongoid/fields/serializable/array.rb +0 -1
- data/lib/mongoid/fields/serializable/boolean.rb +0 -1
- data/lib/mongoid/fields/serializable/float.rb +0 -1
- data/lib/mongoid/fields/serializable/integer.rb +1 -2
- data/lib/mongoid/fields/serializable/object_id.rb +0 -1
- data/lib/mongoid/fields/serializable/string.rb +0 -1
- data/lib/mongoid/fields/serializable/symbol.rb +0 -1
- data/lib/mongoid/matchers/strategies.rb +25 -2
- data/lib/mongoid/nested_attributes.rb +1 -1
- data/lib/mongoid/persistence/atomic.rb +2 -2
- data/lib/mongoid/persistence/atomic/{set.rb → sets.rb} +1 -1
- data/lib/mongoid/persistence/deletion.rb +1 -1
- data/lib/mongoid/relations/bindings/referenced/in.rb +5 -5
- data/lib/mongoid/relations/bindings/referenced/many.rb +4 -4
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +2 -2
- data/lib/mongoid/relations/bindings/referenced/one.rb +4 -4
- data/lib/mongoid/relations/builder.rb +1 -2
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +5 -4
- data/lib/mongoid/relations/builders/nested_attributes/one.rb +1 -1
- data/lib/mongoid/relations/builders/referenced/many.rb +4 -2
- data/lib/mongoid/relations/cascading/destroy.rb +8 -1
- data/lib/mongoid/relations/embedded/in.rb +1 -1
- data/lib/mongoid/relations/embedded/many.rb +15 -2
- data/lib/mongoid/relations/embedded/one.rb +1 -1
- data/lib/mongoid/relations/nested_builder.rb +11 -4
- data/lib/mongoid/relations/referenced/many.rb +4 -2
- data/lib/mongoid/relations/referenced/many_to_many.rb +2 -1
- data/lib/mongoid/relations/synchronization.rb +39 -2
- data/lib/mongoid/relations/targets/enumerable.rb +2 -2
- data/lib/mongoid/serialization.rb +1 -1
- data/lib/mongoid/state.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/versioning.rb +15 -1
- metadata +26 -22
- data/lib/mongoid/criterion/unconvertable.rb +0 -20
@@ -50,6 +50,20 @@ module Mongoid # :nodoc:
|
|
50
50
|
!!synced[foreign_key]
|
51
51
|
end
|
52
52
|
|
53
|
+
# Update the inverse keys on destroy.
|
54
|
+
#
|
55
|
+
# @example Update the inverse keys.
|
56
|
+
# document.remove_inverse_keys(metadata)
|
57
|
+
#
|
58
|
+
# @param [ Metadata ] meta The document metadata.
|
59
|
+
#
|
60
|
+
# @return [ Object ] The updated values.
|
61
|
+
#
|
62
|
+
# @since 2.2.1
|
63
|
+
def remove_inverse_keys(meta)
|
64
|
+
meta.criteria(send(meta.foreign_key)).pull(meta.inverse_foreign_key, id)
|
65
|
+
end
|
66
|
+
|
53
67
|
# Update the inverse keys for the relation.
|
54
68
|
#
|
55
69
|
# @example Update the inverse keys
|
@@ -63,8 +77,9 @@ module Mongoid # :nodoc:
|
|
63
77
|
def update_inverse_keys(meta)
|
64
78
|
return unless changes.has_key?(meta.foreign_key)
|
65
79
|
old, new = changes[meta.foreign_key]
|
66
|
-
|
67
|
-
meta.criteria(
|
80
|
+
adds, subs = new - old, old - new
|
81
|
+
meta.criteria(adds).add_to_set(meta.inverse_foreign_key, id) unless adds.empty?
|
82
|
+
meta.criteria(subs).pull(meta.inverse_foreign_key, id) unless subs.empty?
|
68
83
|
end
|
69
84
|
|
70
85
|
module ClassMethods #:nodoc:
|
@@ -79,6 +94,7 @@ module Mongoid # :nodoc:
|
|
79
94
|
# @since 2.1.0
|
80
95
|
def synced(metadata)
|
81
96
|
synced_save(metadata)
|
97
|
+
synced_destroy(metadata)
|
82
98
|
end
|
83
99
|
|
84
100
|
private
|
@@ -108,6 +124,27 @@ module Mongoid # :nodoc:
|
|
108
124
|
end
|
109
125
|
end
|
110
126
|
end
|
127
|
+
|
128
|
+
# Set up the sync of inverse keys that needs to happen on a destroy.
|
129
|
+
#
|
130
|
+
# @example Set up the destroy syncing.
|
131
|
+
# Person.synced_destroy(metadata)
|
132
|
+
#
|
133
|
+
# @param [ Metadata ] metadata The relation metadata.
|
134
|
+
#
|
135
|
+
# @return [ Class ] The class getting set up.
|
136
|
+
#
|
137
|
+
# @since 2.2.1
|
138
|
+
def synced_destroy(metadata)
|
139
|
+
tap do
|
140
|
+
set_callback(
|
141
|
+
:destroy,
|
142
|
+
:after
|
143
|
+
) do |doc|
|
144
|
+
doc.remove_inverse_keys(metadata)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
111
148
|
end
|
112
149
|
end
|
113
150
|
end
|
@@ -156,7 +156,7 @@ module Mongoid #:nodoc:
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
added.each do |doc|
|
159
|
-
next
|
159
|
+
next if doc.persisted? && (!loaded? && !loaded.empty?)
|
160
160
|
yield(doc)
|
161
161
|
end
|
162
162
|
@executed = true
|
@@ -316,7 +316,7 @@ module Mongoid #:nodoc:
|
|
316
316
|
#
|
317
317
|
# @since 2.1.0
|
318
318
|
def size
|
319
|
-
(
|
319
|
+
(unloaded ? unloaded.count : loaded.count) + added.count{ |d| d.new? }
|
320
320
|
end
|
321
321
|
alias :length :size
|
322
322
|
|
data/lib/mongoid/state.rb
CHANGED
data/lib/mongoid/version.rb
CHANGED
data/lib/mongoid/versioning.rb
CHANGED
@@ -53,6 +53,20 @@ module Mongoid #:nodoc:
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
# Forces the creation of a new version of the +Document+, regardless of
|
57
|
+
# whether a change was actually made.
|
58
|
+
#
|
59
|
+
# @example Revise the document.
|
60
|
+
# person.revise!
|
61
|
+
#
|
62
|
+
# @since 2.2.1
|
63
|
+
def revise!
|
64
|
+
new_version = versions.build((previous_revision || self).versioned_attributes)
|
65
|
+
versions.shift if version_max.present? && versions.length > version_max
|
66
|
+
self.version = (version || 1 ) + 1
|
67
|
+
save
|
68
|
+
end
|
69
|
+
|
56
70
|
# Filters the results of +changes+ by removing any fields that should
|
57
71
|
# not be versioned.
|
58
72
|
#
|
@@ -153,7 +167,7 @@ module Mongoid #:nodoc:
|
|
153
167
|
# @since 2.1.0
|
154
168
|
def only_versioned_attributes(hash)
|
155
169
|
{}.tap do |versioned|
|
156
|
-
hash.each_pair do |name, value|
|
170
|
+
hash.except("versions").each_pair do |name, value|
|
157
171
|
field = fields[name]
|
158
172
|
versioned[name] = value if !field || field.versioned?
|
159
173
|
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.2.
|
4
|
+
version: 2.2.1
|
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: 2011-
|
12
|
+
date: 2011-09-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
16
|
-
requirement: &
|
16
|
+
requirement: &70136033446360 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70136033446360
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: tzinfo
|
27
|
-
requirement: &
|
27
|
+
requirement: &70136033445580 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,21 +32,24 @@ dependencies:
|
|
32
32
|
version: 0.3.22
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70136033445580
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: mongo
|
38
|
-
requirement: &
|
38
|
+
requirement: &70136033444420 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ! '>='
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '1.3'
|
44
|
+
- - <
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.4'
|
44
47
|
type: :runtime
|
45
48
|
prerelease: false
|
46
|
-
version_requirements: *
|
49
|
+
version_requirements: *70136033444420
|
47
50
|
- !ruby/object:Gem::Dependency
|
48
51
|
name: rdoc
|
49
|
-
requirement: &
|
52
|
+
requirement: &70136033443180 !ruby/object:Gem::Requirement
|
50
53
|
none: false
|
51
54
|
requirements:
|
52
55
|
- - ~>
|
@@ -54,10 +57,10 @@ dependencies:
|
|
54
57
|
version: 3.5.0
|
55
58
|
type: :development
|
56
59
|
prerelease: false
|
57
|
-
version_requirements: *
|
60
|
+
version_requirements: *70136033443180
|
58
61
|
- !ruby/object:Gem::Dependency
|
59
62
|
name: bson_ext
|
60
|
-
requirement: &
|
63
|
+
requirement: &70136033442040 !ruby/object:Gem::Requirement
|
61
64
|
none: false
|
62
65
|
requirements:
|
63
66
|
- - ~>
|
@@ -65,10 +68,10 @@ dependencies:
|
|
65
68
|
version: '1.3'
|
66
69
|
type: :development
|
67
70
|
prerelease: false
|
68
|
-
version_requirements: *
|
71
|
+
version_requirements: *70136033442040
|
69
72
|
- !ruby/object:Gem::Dependency
|
70
73
|
name: mocha
|
71
|
-
requirement: &
|
74
|
+
requirement: &70136033440960 !ruby/object:Gem::Requirement
|
72
75
|
none: false
|
73
76
|
requirements:
|
74
77
|
- - ~>
|
@@ -76,10 +79,10 @@ dependencies:
|
|
76
79
|
version: 0.9.12
|
77
80
|
type: :development
|
78
81
|
prerelease: false
|
79
|
-
version_requirements: *
|
82
|
+
version_requirements: *70136033440960
|
80
83
|
- !ruby/object:Gem::Dependency
|
81
84
|
name: rspec
|
82
|
-
requirement: &
|
85
|
+
requirement: &70136033439820 !ruby/object:Gem::Requirement
|
83
86
|
none: false
|
84
87
|
requirements:
|
85
88
|
- - ~>
|
@@ -87,10 +90,10 @@ dependencies:
|
|
87
90
|
version: '2.6'
|
88
91
|
type: :development
|
89
92
|
prerelease: false
|
90
|
-
version_requirements: *
|
93
|
+
version_requirements: *70136033439820
|
91
94
|
- !ruby/object:Gem::Dependency
|
92
95
|
name: watchr
|
93
|
-
requirement: &
|
96
|
+
requirement: &70136033438380 !ruby/object:Gem::Requirement
|
94
97
|
none: false
|
95
98
|
requirements:
|
96
99
|
- - ~>
|
@@ -98,7 +101,7 @@ dependencies:
|
|
98
101
|
version: '0.6'
|
99
102
|
type: :development
|
100
103
|
prerelease: false
|
101
|
-
version_requirements: *
|
104
|
+
version_requirements: *70136033438380
|
102
105
|
description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
|
103
106
|
in Ruby.
|
104
107
|
email:
|
@@ -161,7 +164,6 @@ files:
|
|
161
164
|
- lib/mongoid/criterion/inspection.rb
|
162
165
|
- lib/mongoid/criterion/optional.rb
|
163
166
|
- lib/mongoid/criterion/selector.rb
|
164
|
-
- lib/mongoid/criterion/unconvertable.rb
|
165
167
|
- lib/mongoid/cursor.rb
|
166
168
|
- lib/mongoid/default_scope.rb
|
167
169
|
- lib/mongoid/dirty.rb
|
@@ -186,6 +188,7 @@ files:
|
|
186
188
|
- lib/mongoid/extensions/false_class/equality.rb
|
187
189
|
- lib/mongoid/extensions/hash/criteria_helpers.rb
|
188
190
|
- lib/mongoid/extensions/hash/scoping.rb
|
191
|
+
- lib/mongoid/extensions/integer/checks.rb
|
189
192
|
- lib/mongoid/extensions/nil/collectionization.rb
|
190
193
|
- lib/mongoid/extensions/object/checks.rb
|
191
194
|
- lib/mongoid/extensions/object/reflections.rb
|
@@ -193,6 +196,7 @@ files:
|
|
193
196
|
- lib/mongoid/extensions/object/yoda.rb
|
194
197
|
- lib/mongoid/extensions/object_id/conversions.rb
|
195
198
|
- lib/mongoid/extensions/proc/scoping.rb
|
199
|
+
- lib/mongoid/extensions/string/checks.rb
|
196
200
|
- lib/mongoid/extensions/string/conversions.rb
|
197
201
|
- lib/mongoid/extensions/string/inflections.rb
|
198
202
|
- lib/mongoid/extensions/symbol/inflections.rb
|
@@ -267,7 +271,7 @@ files:
|
|
267
271
|
- lib/mongoid/persistence/atomic/push.rb
|
268
272
|
- lib/mongoid/persistence/atomic/push_all.rb
|
269
273
|
- lib/mongoid/persistence/atomic/rename.rb
|
270
|
-
- lib/mongoid/persistence/atomic/
|
274
|
+
- lib/mongoid/persistence/atomic/sets.rb
|
271
275
|
- lib/mongoid/persistence/atomic/unset.rb
|
272
276
|
- lib/mongoid/persistence/atomic.rb
|
273
277
|
- lib/mongoid/persistence/deletion.rb
|
@@ -384,7 +388,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
384
388
|
version: '0'
|
385
389
|
segments:
|
386
390
|
- 0
|
387
|
-
hash:
|
391
|
+
hash: 3997568018995098764
|
388
392
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
389
393
|
none: false
|
390
394
|
requirements:
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Mongoid #:nodoc:
|
3
|
-
module Criterion #:nodoc:
|
4
|
-
|
5
|
-
# Wrapper class for strings that should not be converted into
|
6
|
-
# BSON::ObjectIds.
|
7
|
-
class Unconvertable < String
|
8
|
-
|
9
|
-
# Initialize just like a normal string, and quack like it to.
|
10
|
-
#
|
11
|
-
# @example Create the new Unconvertable.
|
12
|
-
# Unconvertable.new("testing")
|
13
|
-
#
|
14
|
-
# @param [ String ] value The string.
|
15
|
-
#
|
16
|
-
# @since 2.0.2
|
17
|
-
def initialize(value); super; end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|