mongoid 2.1.9 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +281 -0
- data/{README.rdoc → README.md} +24 -14
- data/Rakefile +1 -1
- data/lib/config/locales/bg.yml +5 -0
- data/lib/config/locales/de.yml +5 -0
- data/lib/config/locales/en-GB.yml +5 -0
- data/lib/config/locales/en.yml +5 -0
- data/lib/config/locales/es.yml +3 -0
- data/lib/config/locales/fr.yml +5 -0
- data/lib/config/locales/hi.yml +5 -0
- data/lib/config/locales/hu.yml +5 -0
- data/lib/config/locales/id.yml +5 -0
- data/lib/config/locales/it.yml +5 -0
- data/lib/config/locales/ja.yml +5 -0
- data/lib/config/locales/kr.yml +5 -0
- data/lib/config/locales/nl.yml +5 -0
- data/lib/config/locales/pl.yml +5 -0
- data/lib/config/locales/pt-BR.yml +5 -0
- data/lib/config/locales/pt.yml +5 -0
- data/lib/config/locales/ro.yml +5 -0
- data/lib/config/locales/ru.yml +5 -0
- data/lib/config/locales/sv.yml +5 -0
- data/lib/config/locales/vi.yml +5 -0
- data/lib/config/locales/zh-CN.yml +5 -0
- data/lib/mongoid/atomic.rb +61 -10
- data/lib/mongoid/atomic/modifiers.rb +156 -24
- data/lib/mongoid/attributes.rb +38 -10
- data/lib/mongoid/collection.rb +21 -3
- data/lib/mongoid/collections.rb +52 -6
- data/lib/mongoid/collections/master.rb +8 -2
- data/lib/mongoid/collections/operations.rb +1 -0
- data/lib/mongoid/config.rb +5 -2
- data/lib/mongoid/config/database.rb +15 -2
- data/lib/mongoid/contexts/mongo.rb +3 -0
- data/lib/mongoid/criteria.rb +27 -3
- data/lib/mongoid/criterion/inclusion.rb +58 -0
- data/lib/mongoid/dirty.rb +2 -0
- data/lib/mongoid/document.rb +23 -0
- data/lib/mongoid/errors.rb +3 -0
- data/lib/mongoid/errors/callback.rb +26 -0
- data/lib/mongoid/errors/eager_load.rb +25 -0
- data/lib/mongoid/errors/invalid_find.rb +19 -0
- data/lib/mongoid/extensions.rb +3 -1
- data/lib/mongoid/extensions/object_id/conversions.rb +1 -1
- data/lib/mongoid/extras.rb +12 -2
- data/lib/mongoid/fields.rb +41 -2
- data/lib/mongoid/fields/serializable.rb +36 -0
- data/lib/mongoid/fields/serializable/foreign_keys/array.rb +13 -14
- data/lib/mongoid/fields/serializable/foreign_keys/object.rb +13 -14
- data/lib/mongoid/finders.rb +4 -4
- data/lib/mongoid/identity_map.rb +33 -20
- data/lib/mongoid/keys.rb +24 -1
- data/lib/mongoid/nested_attributes.rb +16 -4
- data/lib/mongoid/persistence.rb +50 -6
- data/lib/mongoid/persistence/operations.rb +1 -4
- data/lib/mongoid/persistence/operations/update.rb +3 -1
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +27 -44
- data/lib/mongoid/relations/builders/referenced/many.rb +2 -1
- data/lib/mongoid/relations/builders/referenced/one.rb +1 -1
- data/lib/mongoid/relations/cascading.rb +12 -1
- data/lib/mongoid/relations/embedded/many.rb +11 -4
- data/lib/mongoid/relations/embedded/one.rb +6 -2
- data/lib/mongoid/relations/macros.rb +19 -12
- data/lib/mongoid/relations/metadata.rb +17 -0
- data/lib/mongoid/relations/polymorphic.rb +12 -1
- data/lib/mongoid/relations/proxy.rb +24 -0
- data/lib/mongoid/relations/referenced/in.rb +20 -0
- data/lib/mongoid/relations/referenced/many.rb +30 -6
- data/lib/mongoid/relations/referenced/many_to_many.rb +18 -2
- data/lib/mongoid/relations/referenced/one.rb +19 -0
- data/lib/mongoid/relations/reflections.rb +23 -3
- data/lib/mongoid/relations/targets/enumerable.rb +29 -1
- data/lib/mongoid/serialization.rb +1 -1
- data/lib/mongoid/sharding.rb +12 -2
- data/lib/mongoid/threaded.rb +98 -0
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/versioning.rb +12 -2
- metadata +25 -21
data/lib/config/locales/hu.yml
CHANGED
@@ -4,8 +4,13 @@ hu:
|
|
4
4
|
messages:
|
5
5
|
taken:
|
6
6
|
már foglalt
|
7
|
+
callbacks:
|
8
|
+
"Calling %{method} on %{klass} resulted in a false return from a callback."
|
7
9
|
document_not_found:
|
8
10
|
"%{klass} osztályban, %{identifiers} id(k)-el nem található dokumentum."
|
11
|
+
eager_load:
|
12
|
+
"Eager loading :%{name} is not supported due to it being a many-to-many
|
13
|
+
or polymorphic belongs_to relation."
|
9
14
|
invalid_database:
|
10
15
|
Az adatbázisnak Mongo::DB-nek kellene lennie, nem %{name}.
|
11
16
|
invalid_type:
|
data/lib/config/locales/id.yml
CHANGED
@@ -4,8 +4,13 @@ id:
|
|
4
4
|
messages:
|
5
5
|
taken:
|
6
6
|
telah digunakan
|
7
|
+
callbacks:
|
8
|
+
"Calling %{method} on %{klass} resulted in a false return from a callback."
|
7
9
|
document_not_found:
|
8
10
|
Dokumen tidak ditemukan untuk kelas %{klass} dengan id %{identifiers}.
|
11
|
+
eager_load:
|
12
|
+
"Eager loading :%{name} is not supported due to it being a many-to-many
|
13
|
+
or polymorphic belongs_to relation."
|
9
14
|
invalid_database:
|
10
15
|
Database harus Mongo::DB, bukan %{name}.
|
11
16
|
invalid_type:
|
data/lib/config/locales/it.yml
CHANGED
@@ -4,8 +4,13 @@ it:
|
|
4
4
|
messages:
|
5
5
|
taken:
|
6
6
|
è già utilizzato
|
7
|
+
callbacks:
|
8
|
+
"Calling %{method} on %{klass} resulted in a false return from a callback."
|
7
9
|
document_not_found:
|
8
10
|
Documento non trovato per la classe %{klass} con id(s) %{identifiers}.
|
11
|
+
eager_load:
|
12
|
+
"Eager loading :%{name} is not supported due to it being a many-to-many
|
13
|
+
or polymorphic belongs_to relation."
|
9
14
|
invalid_database:
|
10
15
|
Il database dovrebbe essere un Mongo::DB, non %{name}.
|
11
16
|
invalid_type:
|
data/lib/config/locales/ja.yml
CHANGED
@@ -4,8 +4,13 @@ ja:
|
|
4
4
|
messages:
|
5
5
|
taken:
|
6
6
|
はすでに使用されています
|
7
|
+
callbacks:
|
8
|
+
"Calling %{method} on %{klass} resulted in a false return from a callback."
|
7
9
|
document_not_found:
|
8
10
|
次のDocumentは見つかりませんでした。class %{klass} with id(s) %{identifiers}
|
11
|
+
eager_load:
|
12
|
+
"Eager loading :%{name} is not supported due to it being a many-to-many
|
13
|
+
or polymorphic belongs_to relation."
|
9
14
|
invalid_database:
|
10
15
|
次のDatabaseは利用できませんでした。%{name}
|
11
16
|
invalid_type:
|
data/lib/config/locales/kr.yml
CHANGED
@@ -4,8 +4,13 @@ kr:
|
|
4
4
|
messages:
|
5
5
|
taken:
|
6
6
|
이미 사용하고있습니다
|
7
|
+
callbacks:
|
8
|
+
"Calling %{method} on %{klass} resulted in a false return from a callback."
|
7
9
|
document_not_found:
|
8
10
|
클라스 %{klass}와 id를 %{identifiers} 위한 문서를 찾을수 없습니다.
|
11
|
+
eager_load:
|
12
|
+
"Eager loading :%{name} is not supported due to it being a many-to-many
|
13
|
+
or polymorphic belongs_to relation."
|
9
14
|
invalid_database:
|
10
15
|
데이타베이스가 Mongo::DB이어야 합니다, %{name}이면 안됩니다.
|
11
16
|
invalid_type:
|
data/lib/config/locales/nl.yml
CHANGED
@@ -4,8 +4,13 @@ nl:
|
|
4
4
|
messages:
|
5
5
|
taken:
|
6
6
|
al in gebruik
|
7
|
+
callbacks:
|
8
|
+
"Calling %{method} on %{klass} resulted in a false return from a callback."
|
7
9
|
document_not_found:
|
8
10
|
Document niet gevonden voor class %{klass} met de id(s) %{identifiers}.
|
11
|
+
eager_load:
|
12
|
+
"Eager loading :%{name} is not supported due to it being a many-to-many
|
13
|
+
or polymorphic belongs_to relation."
|
9
14
|
invalid_database:
|
10
15
|
Database moet een Mongo::DB zijn, niet een %{name}.
|
11
16
|
invalid_type:
|
data/lib/config/locales/pl.yml
CHANGED
@@ -4,8 +4,13 @@ pl:
|
|
4
4
|
messages:
|
5
5
|
taken:
|
6
6
|
jest już zajęte
|
7
|
+
callbacks:
|
8
|
+
"Calling %{method} on %{klass} resulted in a false return from a callback."
|
7
9
|
document_not_found:
|
8
10
|
Nie znaleziono dokumentu dla klasy %{klass} o id %{identifiers}.
|
11
|
+
eager_load:
|
12
|
+
"Eager loading :%{name} is not supported due to it being a many-to-many
|
13
|
+
or polymorphic belongs_to relation."
|
9
14
|
invalid_database:
|
10
15
|
Baza danych powinna być typu Mongo::DB, a nie %{name}.
|
11
16
|
invalid_type:
|
@@ -4,8 +4,13 @@ pt-BR:
|
|
4
4
|
messages:
|
5
5
|
taken:
|
6
6
|
já está utilizada
|
7
|
+
callbacks:
|
8
|
+
"Calling %{method} on %{klass} resulted in a false return from a callback."
|
7
9
|
document_not_found:
|
8
10
|
Nenhum documento encontrado para a classe %{klass} com os id(s) %{identifiers}.
|
11
|
+
eager_load:
|
12
|
+
"Eager loading :%{name} is not supported due to it being a many-to-many
|
13
|
+
or polymorphic belongs_to relation."
|
9
14
|
invalid_database:
|
10
15
|
A base de dados deverá ser uma Mongo::DB, em vez de %{name}.
|
11
16
|
invalid_type:
|
data/lib/config/locales/pt.yml
CHANGED
@@ -4,8 +4,13 @@ pt:
|
|
4
4
|
messages:
|
5
5
|
taken:
|
6
6
|
já está utilizada
|
7
|
+
callbacks:
|
8
|
+
"Calling %{method} on %{klass} resulted in a false return from a callback."
|
7
9
|
document_not_found:
|
8
10
|
Nenhum documento encontrado para a classe %{klass} com os id(s) %{identifiers}.
|
11
|
+
eager_load:
|
12
|
+
"Eager loading :%{name} is not supported due to it being a many-to-many
|
13
|
+
or polymorphic belongs_to relation."
|
9
14
|
invalid_database:
|
10
15
|
A base de dados deverá ser uma Mongo::DB, em vez de %{name}.
|
11
16
|
invalid_type:
|
data/lib/config/locales/ro.yml
CHANGED
@@ -4,8 +4,13 @@ ro:
|
|
4
4
|
messages:
|
5
5
|
taken:
|
6
6
|
este deja folosit
|
7
|
+
callbacks:
|
8
|
+
"Calling %{method} on %{klass} resulted in a false return from a callback."
|
7
9
|
document_not_found:
|
8
10
|
Nu există document în clasa %{klass} cu id %{identifiers}.
|
11
|
+
eager_load:
|
12
|
+
"Eager loading :%{name} is not supported due to it being a many-to-many
|
13
|
+
or polymorphic belongs_to relation."
|
9
14
|
invalid_database:
|
10
15
|
Baza de date ar trebui să fie de tipul Mongo::DB, nu %{name}.
|
11
16
|
invalid_type:
|
data/lib/config/locales/ru.yml
CHANGED
@@ -4,8 +4,13 @@ ru:
|
|
4
4
|
messages:
|
5
5
|
taken:
|
6
6
|
уже занят
|
7
|
+
callbacks:
|
8
|
+
"Calling %{method} on %{klass} resulted in a false return from a callback."
|
7
9
|
document_not_found:
|
8
10
|
Документ класса %{klass} с id %{identifiers} не найден.
|
11
|
+
eager_load:
|
12
|
+
"Eager loading :%{name} is not supported due to it being a many-to-many
|
13
|
+
or polymorphic belongs_to relation."
|
9
14
|
invalid_database:
|
10
15
|
База данных должна быть Mongo::DB, а не %{name}.
|
11
16
|
invalid_type:
|
data/lib/config/locales/sv.yml
CHANGED
@@ -4,8 +4,13 @@ sv:
|
|
4
4
|
messages:
|
5
5
|
taken:
|
6
6
|
har redan använts
|
7
|
+
callbacks:
|
8
|
+
"Calling %{method} on %{klass} resulted in a false return from a callback."
|
7
9
|
document_not_found:
|
8
10
|
Inget dokument kunde hittas för klass %{klass} med id %{identifiers}.
|
11
|
+
eager_load:
|
12
|
+
"Eager loading :%{name} is not supported due to it being a many-to-many
|
13
|
+
or polymorphic belongs_to relation."
|
9
14
|
invalid_database:
|
10
15
|
Databasen bör vara Mongo::DB, inte %{name}.
|
11
16
|
invalid_type:
|
data/lib/config/locales/vi.yml
CHANGED
@@ -4,8 +4,13 @@ vi:
|
|
4
4
|
messages:
|
5
5
|
taken:
|
6
6
|
đã bị lấy
|
7
|
+
callbacks:
|
8
|
+
"Calling %{method} on %{klass} resulted in a false return from a callback."
|
7
9
|
document_not_found:
|
8
10
|
Không tìm thấy văn bản cho lớp %{klass} với định danh %{identifiers}.
|
11
|
+
eager_load:
|
12
|
+
"Eager loading :%{name} is not supported due to it being a many-to-many
|
13
|
+
or polymorphic belongs_to relation."
|
9
14
|
invalid_database:
|
10
15
|
Cơ sở dữ liệu nên là Mongo::DB, không phải %{name}.
|
11
16
|
invalid_type:
|
@@ -4,10 +4,15 @@ zh-CN:
|
|
4
4
|
messages:
|
5
5
|
blank:
|
6
6
|
不能为空
|
7
|
+
callbacks:
|
8
|
+
"Calling %{method} on %{klass} resulted in a false return from a callback."
|
7
9
|
taken:
|
8
10
|
已占用
|
9
11
|
document_not_found:
|
10
12
|
没有发现类是%{klass}id(s)是%{identifiers}的文档
|
13
|
+
eager_load:
|
14
|
+
"Eager loading :%{name} is not supported due to it being a many-to-many
|
15
|
+
or polymorphic belongs_to relation."
|
11
16
|
invalid_database:
|
12
17
|
数据库应该是Mongo::DB,而不是%{name}.
|
13
18
|
invalid_type:
|
data/lib/mongoid/atomic.rb
CHANGED
@@ -41,10 +41,9 @@ module Mongoid #:nodoc:
|
|
41
41
|
# @since 2.1.0
|
42
42
|
def atomic_updates
|
43
43
|
Modifiers.new.tap do |mods|
|
44
|
-
mods
|
44
|
+
generate_atomic_updates(mods, self)
|
45
45
|
_children.each do |child|
|
46
|
-
mods
|
47
|
-
mods.push(child.atomic_pushes)
|
46
|
+
generate_atomic_updates(mods, child)
|
48
47
|
end
|
49
48
|
end
|
50
49
|
end
|
@@ -54,7 +53,7 @@ module Mongoid #:nodoc:
|
|
54
53
|
# documents, $unset on embeds_one, $set on embeds_many.
|
55
54
|
#
|
56
55
|
# @example Get the removal operator.
|
57
|
-
# name.
|
56
|
+
# name.atomic_delete_modifier
|
58
57
|
#
|
59
58
|
# @return [ String ] The pull or unset operation.
|
60
59
|
def atomic_delete_modifier
|
@@ -65,7 +64,7 @@ module Mongoid #:nodoc:
|
|
65
64
|
# documents, $set on embeds_one, $push on embeds_many.
|
66
65
|
#
|
67
66
|
# @example Get the insert operation.
|
68
|
-
# name.
|
67
|
+
# name.atomic_insert_modifier
|
69
68
|
#
|
70
69
|
# @return [ String ] The pull or set operator.
|
71
70
|
def atomic_insert_modifier
|
@@ -76,7 +75,7 @@ module Mongoid #:nodoc:
|
|
76
75
|
# updates via $set in MongoDB.
|
77
76
|
#
|
78
77
|
# @example Get the path to this document.
|
79
|
-
# address.
|
78
|
+
# address.atomic_path
|
80
79
|
#
|
81
80
|
# @return [ String ] The path to the document in the database.
|
82
81
|
def atomic_path
|
@@ -86,17 +85,41 @@ module Mongoid #:nodoc:
|
|
86
85
|
# Returns the positional operator of this document for modification.
|
87
86
|
#
|
88
87
|
# @example Get the positional operator.
|
89
|
-
# address.
|
88
|
+
# address.atomic_position
|
90
89
|
#
|
91
90
|
# @return [ String ] The positional operator with indexes.
|
92
91
|
def atomic_position
|
93
92
|
atomic_paths.position
|
94
93
|
end
|
95
94
|
|
95
|
+
# Get all the attributes that need to be pulled.
|
96
|
+
#
|
97
|
+
# @example Get the pulls.
|
98
|
+
# person.atomic_pulls
|
99
|
+
#
|
100
|
+
# @return [ Array<Hash> ] The $pullAll operations.
|
101
|
+
#
|
102
|
+
# @since 2.2.0
|
103
|
+
def atomic_pulls
|
104
|
+
@atomic_pulls ||= {}
|
105
|
+
end
|
106
|
+
|
107
|
+
# Add the document as an atomic pull.
|
108
|
+
#
|
109
|
+
# @example Add the atomic pull.
|
110
|
+
# person.add_atomic_pull(address)
|
111
|
+
#
|
112
|
+
# @param [ Document ] The embedded document to pull.
|
113
|
+
#
|
114
|
+
# @since 2.2.0
|
115
|
+
def add_atomic_pull(document)
|
116
|
+
(atomic_pulls[document.atomic_path] ||= []).push(document.as_document)
|
117
|
+
end
|
118
|
+
|
96
119
|
# Get all the push attributes that need to occur.
|
97
120
|
#
|
98
121
|
# @example Get the pushes.
|
99
|
-
# person.
|
122
|
+
# person.atomic_pushes
|
100
123
|
#
|
101
124
|
# @return [ Hash ] The $pushAll operations.
|
102
125
|
#
|
@@ -109,7 +132,7 @@ module Mongoid #:nodoc:
|
|
109
132
|
# with MongoDB's $ operator.
|
110
133
|
#
|
111
134
|
# @example Get the selector.
|
112
|
-
# address.
|
135
|
+
# address.atomic_selector
|
113
136
|
#
|
114
137
|
# @return [ String ] The exact selector for this document.
|
115
138
|
def atomic_selector
|
@@ -119,7 +142,7 @@ module Mongoid #:nodoc:
|
|
119
142
|
# Get all the attributes that need to be set.
|
120
143
|
#
|
121
144
|
# @example Get the sets.
|
122
|
-
# person.
|
145
|
+
# person.atomic_sets
|
123
146
|
#
|
124
147
|
# @return [ Hash ] The $set operations.
|
125
148
|
#
|
@@ -128,6 +151,18 @@ module Mongoid #:nodoc:
|
|
128
151
|
updateable? ? setters : settable? ? { atomic_path => as_document } : {}
|
129
152
|
end
|
130
153
|
|
154
|
+
# Get all the attributes that need to be unset.
|
155
|
+
#
|
156
|
+
# @example Get the unsets.
|
157
|
+
# person.atomic_unsets
|
158
|
+
#
|
159
|
+
# @return [ Array<Hash> ] The $unset operations.
|
160
|
+
#
|
161
|
+
# @since 2.2.0
|
162
|
+
def atomic_unsets
|
163
|
+
@atomic_unsets ||= []
|
164
|
+
end
|
165
|
+
|
131
166
|
private
|
132
167
|
|
133
168
|
# Get the atomic paths utility for this document.
|
@@ -141,5 +176,21 @@ module Mongoid #:nodoc:
|
|
141
176
|
def atomic_paths
|
142
177
|
@atomic_paths ||= metadata ? metadata.path(self) : Atomic::Paths::Root.new(self)
|
143
178
|
end
|
179
|
+
|
180
|
+
# Generates the atomic updates in the correct order.
|
181
|
+
#
|
182
|
+
# @example Generate the updates.
|
183
|
+
# model.generate_atomic_updates(mods, doc)
|
184
|
+
#
|
185
|
+
# @param [ Modifiers ] mods The atomic modifications.
|
186
|
+
# @param [ Document ] doc The document to update for.
|
187
|
+
#
|
188
|
+
# @since 2.2.0
|
189
|
+
def generate_atomic_updates(mods, doc)
|
190
|
+
mods.unset(doc.atomic_unsets)
|
191
|
+
mods.pull(doc.atomic_pulls)
|
192
|
+
mods.set(doc.atomic_sets)
|
193
|
+
mods.push(doc.atomic_pushes)
|
194
|
+
end
|
144
195
|
end
|
145
196
|
end
|
@@ -6,6 +6,21 @@ module Mongoid #:nodoc:
|
|
6
6
|
# database.
|
7
7
|
class Modifiers < Hash
|
8
8
|
|
9
|
+
# Adds pull modifiers to the modifiers hash.
|
10
|
+
#
|
11
|
+
# @example Add pull operations.
|
12
|
+
# modifiers.pull({ "addresses" => { "street" => "Bond" }})
|
13
|
+
#
|
14
|
+
# @param [ Hash ] modifications The pull modifiers.
|
15
|
+
#
|
16
|
+
# @since 2.2.0
|
17
|
+
def pull(modifications)
|
18
|
+
modifications.each_pair do |field, value|
|
19
|
+
add_operation(pulls, field, value)
|
20
|
+
pull_fields << field.split(".", 2)[0]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
9
24
|
# Adds push modifiers to the modifiers hash.
|
10
25
|
#
|
11
26
|
# @example Add push operations.
|
@@ -16,12 +31,8 @@ module Mongoid #:nodoc:
|
|
16
31
|
# @since 2.1.0
|
17
32
|
def push(modifications)
|
18
33
|
modifications.each_pair do |field, value|
|
19
|
-
mods =
|
20
|
-
|
21
|
-
mods[field].push(value)
|
22
|
-
else
|
23
|
-
mods[field] = [ value ]
|
24
|
-
end
|
34
|
+
mods = push_conflict?(field) ? conflicting_pushes : pushes
|
35
|
+
add_operation(mods, field, Array.wrap(value))
|
25
36
|
end
|
26
37
|
end
|
27
38
|
|
@@ -36,26 +47,111 @@ module Mongoid #:nodoc:
|
|
36
47
|
def set(modifications)
|
37
48
|
modifications.each_pair do |field, value|
|
38
49
|
next if field == "_id"
|
39
|
-
|
40
|
-
|
50
|
+
mods = set_conflict?(field) ? conflicting_sets : sets
|
51
|
+
add_operation(mods, field, value)
|
52
|
+
set_fields << field.split(".", 2)[0]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Adds unset operations to the modifiers hash.
|
57
|
+
#
|
58
|
+
# @example Add unset operations.
|
59
|
+
# modifiers.unset([ "addresses" ])
|
60
|
+
#
|
61
|
+
# @param [ Array<String> ] modifications The unset relation names.
|
62
|
+
#
|
63
|
+
# @since 2.2.0
|
64
|
+
def unset(modifications)
|
65
|
+
modifications.each do |field|
|
66
|
+
unsets.update(field => true)
|
41
67
|
end
|
42
68
|
end
|
43
69
|
|
44
70
|
private
|
45
71
|
|
46
|
-
#
|
47
|
-
#
|
72
|
+
# Add the operation to the modifications, either appending or creating a
|
73
|
+
# new one.
|
48
74
|
#
|
49
|
-
# @example
|
50
|
-
#
|
75
|
+
# @example Add the operation.
|
76
|
+
# modifications.add_operation(mods, field, value)
|
51
77
|
#
|
52
|
-
# @param [
|
78
|
+
# @param [ Hash ] mods The modifications.
|
79
|
+
# @param [ String ] field The field.
|
80
|
+
# @param [ Hash ] value The atomic op.
|
53
81
|
#
|
54
|
-
# @
|
82
|
+
# @since 2.2.0
|
83
|
+
def add_operation(mods, field, value)
|
84
|
+
if mods.has_key?(field)
|
85
|
+
value.each do |val|
|
86
|
+
mods[field].push(val)
|
87
|
+
end
|
88
|
+
else
|
89
|
+
mods[field] = value
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Is the operation going to be a conflict for a $set?
|
55
94
|
#
|
56
|
-
# @
|
57
|
-
|
58
|
-
|
95
|
+
# @example Is this a conflict for a set?
|
96
|
+
# modifiers.set_conflict?(field)
|
97
|
+
#
|
98
|
+
# @param [ String ] field The field.
|
99
|
+
#
|
100
|
+
# @return [ true, false ] If this field is a conflict.
|
101
|
+
#
|
102
|
+
# @since 2.2.0
|
103
|
+
def set_conflict?(field)
|
104
|
+
pull_fields.include?(field.split(".", 2)[0])
|
105
|
+
end
|
106
|
+
|
107
|
+
# Is the operation going to be a conflict for a $push?
|
108
|
+
#
|
109
|
+
# @example Is this a conflict for a push?
|
110
|
+
# modifiers.push_conflict?(field)
|
111
|
+
#
|
112
|
+
# @param [ String ] field The field.
|
113
|
+
#
|
114
|
+
# @return [ true, false ] If this field is a conflict.
|
115
|
+
#
|
116
|
+
# @since 2.2.0
|
117
|
+
def push_conflict?(field)
|
118
|
+
set_fields.include?(field.split(".", 2)[0])
|
119
|
+
end
|
120
|
+
|
121
|
+
# Get the conflicting pull modifications.
|
122
|
+
#
|
123
|
+
# @example Get the conflicting pulls.
|
124
|
+
# modifiers.conflicting_pulls
|
125
|
+
#
|
126
|
+
# @return [ Hash ] The conflicting pull operations.
|
127
|
+
#
|
128
|
+
# @since 2.2.0
|
129
|
+
def conflicting_pulls
|
130
|
+
conflicts["$pullAll"] ||= {}
|
131
|
+
end
|
132
|
+
|
133
|
+
# Get the conflicting push modifications.
|
134
|
+
#
|
135
|
+
# @example Get the conflicting pushs.
|
136
|
+
# modifiers.conflicting_pushs
|
137
|
+
#
|
138
|
+
# @return [ Hash ] The conflicting push operations.
|
139
|
+
#
|
140
|
+
# @since 2.2.0
|
141
|
+
def conflicting_pushes
|
142
|
+
conflicts["$pushAll"] ||= {}
|
143
|
+
end
|
144
|
+
|
145
|
+
# Get the conflicting set modifications.
|
146
|
+
#
|
147
|
+
# @example Get the conflicting sets.
|
148
|
+
# modifiers.conflicting_sets
|
149
|
+
#
|
150
|
+
# @return [ Hash ] The conflicting set operations.
|
151
|
+
#
|
152
|
+
# @since 2.2.0
|
153
|
+
def conflicting_sets
|
154
|
+
conflicts["$set"] ||= {}
|
59
155
|
end
|
60
156
|
|
61
157
|
# Get the push operations that would have conflicted with the sets.
|
@@ -67,19 +163,43 @@ module Mongoid #:nodoc:
|
|
67
163
|
#
|
68
164
|
# @since 2.1.0
|
69
165
|
def conflicts
|
70
|
-
self[:
|
166
|
+
self[:conflicts] ||= {}
|
71
167
|
end
|
72
168
|
|
73
|
-
# Get the
|
169
|
+
# Get the names of the fields that need to be pulled.
|
74
170
|
#
|
75
|
-
# @example Get the fields.
|
76
|
-
# modifiers.
|
171
|
+
# @example Get the pull fields.
|
172
|
+
# modifiers.pull_fields
|
77
173
|
#
|
78
|
-
# @return [ Array ] The
|
174
|
+
# @return [ Array<String> ] The pull fields.
|
175
|
+
#
|
176
|
+
# @since 2.2.0
|
177
|
+
def pull_fields
|
178
|
+
@pull_fields ||= []
|
179
|
+
end
|
180
|
+
|
181
|
+
# Get the names of the fields that need to be set.
|
182
|
+
#
|
183
|
+
# @example Get the set fields.
|
184
|
+
# modifiers.set_fields
|
185
|
+
#
|
186
|
+
# @return [ Array<String> ] The set fields.
|
187
|
+
#
|
188
|
+
# @since 2.2.0
|
189
|
+
def set_fields
|
190
|
+
@set_fields ||= []
|
191
|
+
end
|
192
|
+
|
193
|
+
# Get the $pullAll operations or intialize a new one.
|
194
|
+
#
|
195
|
+
# @example Get the $pullAll operations.
|
196
|
+
# modifiers.pulles
|
197
|
+
#
|
198
|
+
# @return [ Hash ] The $pullAll operations.
|
79
199
|
#
|
80
200
|
# @since 2.1.0
|
81
|
-
def
|
82
|
-
|
201
|
+
def pulls
|
202
|
+
self["$pullAll"] ||= {}
|
83
203
|
end
|
84
204
|
|
85
205
|
# Get the $pushAll operations or intialize a new one.
|
@@ -105,6 +225,18 @@ module Mongoid #:nodoc:
|
|
105
225
|
def sets
|
106
226
|
self["$set"] ||= {}
|
107
227
|
end
|
228
|
+
|
229
|
+
# Get the $unset operations or initialize a new one.
|
230
|
+
#
|
231
|
+
# @example Get the $unset operations.
|
232
|
+
# modifiers.unsets
|
233
|
+
#
|
234
|
+
# @return [ Hash ] The $unset operations.
|
235
|
+
#
|
236
|
+
# @since 2.2.0
|
237
|
+
def unsets
|
238
|
+
self["$unset"] ||= {}
|
239
|
+
end
|
108
240
|
end
|
109
241
|
end
|
110
242
|
end
|