mongoid_versioned_atomic 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mongoid_versioned_atomic/v_atomic.rb +30 -15
- data/lib/mongoid_versioned_atomic/version.rb +1 -1
- data/test/dummy/log/test.log +989 -0
- data/test/v_atomic_test.rb +1 -17
- metadata +1 -9
- data/test/dummy/public/404.html +0 -67
- data/test/dummy/public/422.html +0 -67
- data/test/dummy/public/500.html +0 -66
- data/test/dummy/public/favicon.ico +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 337375f358e129874924ae39cad647f60f56cba7
|
4
|
+
data.tar.gz: 8f74ef7dab61d6612ba465dc2464cb9918c9db2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4fe6168503237763d71060638b69fb67df2cc08a53df03b3bd5e9de305ec0d1b11f4dbebe561c62036d89c7ca78a3b75eca1e1a3ba3ee9d4878b93d93b42b67
|
7
|
+
data.tar.gz: 8ee69f14064cfc0bdb1a2db21f957c06673b670ce1c78d426cd9711f5c5f7914bdbb528876145cf40fda9e63d8c38cf56a41abb49bd911a1303c1ac43320c597
|
@@ -13,9 +13,17 @@ module MongoidVersionedAtomic
|
|
13
13
|
attr_accessor :matched_count
|
14
14
|
attr_accessor :modified_count
|
15
15
|
attr_accessor :upserted_id
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
|
17
|
+
## a flag should be set if this was attempted, and it failed.
|
18
|
+
## if it wasnt even attempted, it shouldnt be a problem.
|
19
|
+
## so before_create => make something on.
|
20
|
+
## after create make it "failed" if on and didnt go through.
|
21
|
+
## otherwise make it nil.
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
#after_create :check_upserted_id
|
26
|
+
#after_update :check_modified_count
|
19
27
|
|
20
28
|
|
21
29
|
end
|
@@ -164,23 +172,33 @@ module MongoidVersionedAtomic
|
|
164
172
|
|
165
173
|
end
|
166
174
|
|
175
|
+
=begin
|
167
176
|
## after create callback , ensures that callback chain is halted if nothing was created.
|
168
177
|
def check_upserted_id
|
169
|
-
|
178
|
+
if !self.upserted_id && self.versioned_create_result
|
179
|
+
self.versioned_create_result = "fail"
|
180
|
+
else
|
181
|
+
self.versioned_create_result = nil
|
182
|
+
end
|
170
183
|
end
|
171
184
|
|
172
185
|
## after update callback ensures that callback chain is halted if nothing was modified.
|
173
186
|
def check_modified_count
|
174
|
-
|
187
|
+
if !self.modified_count == 1 && self.versioned_update_result
|
188
|
+
self.versioned_update_result = "fail"
|
189
|
+
else
|
190
|
+
self.versioned_update_result = nil
|
191
|
+
end
|
175
192
|
end
|
176
|
-
|
193
|
+
=end
|
177
194
|
## overrides the save method on the model.
|
178
195
|
## calls versioned_create if it is a new record
|
179
196
|
## otherwise calls versioned_update.
|
197
|
+
=begin
|
180
198
|
def save(options = {})
|
181
199
|
self.new_record? ? self.versioned_create(options) : self.versioned_update(options)
|
182
200
|
end
|
183
|
-
|
201
|
+
=end
|
184
202
|
|
185
203
|
## @param query[Hash] : optional query hash.
|
186
204
|
## @param log[Boolean] : defaults to false, set true if you want to print out the final command sent to mongo.
|
@@ -223,7 +241,7 @@ module MongoidVersionedAtomic
|
|
223
241
|
|
224
242
|
expected_version = 1
|
225
243
|
|
226
|
-
|
244
|
+
|
227
245
|
prepare_insert(options) do
|
228
246
|
|
229
247
|
as_document.keys.each do |k|
|
@@ -245,6 +263,7 @@ module MongoidVersionedAtomic
|
|
245
263
|
self.matched_count = write_result.matched_count
|
246
264
|
self.modified_count = write_result.modified_count
|
247
265
|
self.upserted_id = write_result.upserted_id
|
266
|
+
|
248
267
|
##as long as it matched a document, or it inserted a document
|
249
268
|
if write_result.matched_count > 0 || write_result.upserted_id
|
250
269
|
self.send("op_success=",true)
|
@@ -256,9 +275,7 @@ module MongoidVersionedAtomic
|
|
256
275
|
|
257
276
|
|
258
277
|
end
|
259
|
-
|
260
|
-
puts "caught db unchanged error, so callbacks will be halted.-------------------------------------------------------------"
|
261
|
-
end
|
278
|
+
|
262
279
|
|
263
280
|
end
|
264
281
|
|
@@ -320,7 +337,7 @@ module MongoidVersionedAtomic
|
|
320
337
|
expected_version = curr_doc["version"] + 1
|
321
338
|
|
322
339
|
##what happens is that we send the update["$set"][k] to whatever was stored in the dirty_fields.
|
323
|
-
|
340
|
+
|
324
341
|
prepare_update(options) do
|
325
342
|
|
326
343
|
dirty_fields.keys.each do |k|
|
@@ -348,9 +365,7 @@ module MongoidVersionedAtomic
|
|
348
365
|
end
|
349
366
|
|
350
367
|
end
|
351
|
-
|
352
|
-
#puts "Rescued db unchanged error, so remaining after update callbacks will be halted."
|
353
|
-
end
|
368
|
+
|
354
369
|
|
355
370
|
end
|
356
371
|
|