mongoo 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/VERSION +1 -1
- data/lib/mongoo/persistence.rb +20 -0
- data/mongoo.gemspec +2 -2
- data/test/test_identity_map.rb +21 -5
- data/test/test_mongoo.rb +14 -0
- metadata +3 -3
data/CHANGELOG
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
data/lib/mongoo/persistence.rb
CHANGED
@@ -58,6 +58,26 @@ module Mongoo
|
|
58
58
|
@collection ||= db.collection(collection_name)
|
59
59
|
end
|
60
60
|
|
61
|
+
# Atomically update and return a document using MongoDB's findAndModify command. (MongoDB > 1.3.0)
|
62
|
+
#
|
63
|
+
# @option opts [Hash] :query ({}) a query selector document for matching the desired document.
|
64
|
+
# @option opts [Hash] :update (nil) the update operation to perform on the matched document.
|
65
|
+
# @option opts [Array, String, OrderedHash] :sort ({}) specify a sort option for the query using any
|
66
|
+
# of the sort options available for Cursor#sort. Sort order is important if the query will be matching
|
67
|
+
# multiple documents since only the first matching document will be updated and returned.
|
68
|
+
# @option opts [Boolean] :remove (false) If true, removes the the returned document from the collection.
|
69
|
+
# @option opts [Boolean] :new (false) If true, returns the updated document; otherwise, returns the document
|
70
|
+
# prior to update.
|
71
|
+
#
|
72
|
+
# @return [Hash] the matched document.
|
73
|
+
#
|
74
|
+
# @core findandmodify find_and_modify-instance_method
|
75
|
+
def find_and_modify(opts)
|
76
|
+
if doc = collection.find_and_modify(opts)
|
77
|
+
Mongoo::Cursor.new(self, nil).obj_from_doc(doc)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
61
81
|
def find(query={}, opts={})
|
62
82
|
Mongoo::Cursor.new(self, collection.find(query, opts))
|
63
83
|
end
|
data/mongoo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongoo}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ben Myles"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-28}
|
13
13
|
s.description = %q{Simple object mapper for MongoDB}
|
14
14
|
s.email = %q{ben.myles@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_identity_map.rb
CHANGED
@@ -8,20 +8,20 @@ class TestIdentityMap < Test::Unit::TestCase
|
|
8
8
|
obj.create_indexes
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
should "be performant" do
|
13
13
|
1.upto(1000) do |i|
|
14
14
|
p = Person.new("name" => "Ben#{i}")
|
15
15
|
p.insert!
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
Mongoo::IdentityMap.on!
|
19
|
-
|
19
|
+
|
20
20
|
all = Person.find.to_a
|
21
|
-
|
21
|
+
|
22
22
|
p = Person.find(name: "Ben5").next
|
23
23
|
assert_equal p.object_id, all[all.index(p)].object_id
|
24
|
-
|
24
|
+
|
25
25
|
Mongoo::IdentityMap.off!
|
26
26
|
end
|
27
27
|
|
@@ -130,4 +130,20 @@ class TestIdentityMap < Test::Unit::TestCase
|
|
130
130
|
|
131
131
|
Mongoo::IdentityMap.off!
|
132
132
|
end
|
133
|
+
|
134
|
+
should "be able to use find_and_modify" do
|
135
|
+
Mongoo::IdentityMap.on!
|
136
|
+
|
137
|
+
p = Person.new(name: "Ben", interests: ["skydiving", "coding"])
|
138
|
+
p.insert!
|
139
|
+
p2 = Person.find_and_modify({
|
140
|
+
query: { name: "Ben" },
|
141
|
+
update: { "$push" => { "interests" => "swimming" } },
|
142
|
+
new: true
|
143
|
+
})
|
144
|
+
assert_equal ["skydiving", "coding", "swimming"], p2.interests
|
145
|
+
assert_equal ["skydiving", "coding", "swimming"], p.interests
|
146
|
+
|
147
|
+
Mongoo::IdentityMap.off!
|
148
|
+
end
|
133
149
|
end
|
data/test/test_mongoo.rb
CHANGED
@@ -337,5 +337,19 @@ class TestMongoo < Test::Unit::TestCase
|
|
337
337
|
assert_equal "people", Person.collection.name
|
338
338
|
assert_equal "spacemen", SpacePerson.collection.name
|
339
339
|
end
|
340
|
+
|
341
|
+
should "be able to use find_and_modify" do
|
342
|
+
p = Person.new(name: "Ben", interests: ["skydiving", "coding"])
|
343
|
+
p.insert!
|
344
|
+
p2 = Person.find_and_modify({
|
345
|
+
query: { name: "Ben" },
|
346
|
+
update: { "$push" => { "interests" => "swimming" } },
|
347
|
+
new: true
|
348
|
+
})
|
349
|
+
assert_equal ["skydiving", "coding", "swimming"], p2.interests
|
350
|
+
assert_equal ["skydiving", "coding"], p.interests
|
351
|
+
p.reload
|
352
|
+
assert_equal ["skydiving", "coding", "swimming"], p.interests
|
353
|
+
end
|
340
354
|
end
|
341
355
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: mongoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ben Myles
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-28 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -197,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
197
197
|
requirements:
|
198
198
|
- - ">="
|
199
199
|
- !ruby/object:Gem::Version
|
200
|
-
hash:
|
200
|
+
hash: 1440689006391132354
|
201
201
|
segments:
|
202
202
|
- 0
|
203
203
|
version: "0"
|