mongoo 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,10 @@
1
- = 0.2.0
1
+ == Changelog
2
+
3
+ === 0.2.1
4
+
5
+ * Identity Map now also stores results from find.to_a, find.each and find.next
6
+
7
+ === 0.2.0
2
8
 
3
9
  * Depends on mongo gem >= 1.3.1
4
10
 
@@ -18,9 +24,9 @@
18
24
 
19
25
  * You can optionally set the collection name on a model now:
20
26
 
21
- class Person < Mongoo::Base
22
- collection_name "spacemen"
23
- end
27
+ class Person < Mongoo::Base
28
+ collection_name "spacemen"
29
+ end
24
30
 
25
31
 
26
32
  * There is a new Identity Map feature available. It will only work when using find_one to
@@ -1,9 +1,49 @@
1
1
  = mongoo
2
2
 
3
- Description goes here.
3
+ == Changelog
4
+
5
+ === 0.2.0
6
+
7
+ * Depends on mongo gem >= 1.3.1
8
+
9
+
10
+ * Can no longer set Mongoo.config = {...}
11
+
12
+ Set Mongoo.conn and Mongoo.db_name instead (more flexibility):
13
+
14
+ Mongoo.conn = Mongo::Connection.new("localhost", 27017, :pool_size => 5, :timeout => 5)
15
+ Mongoo.db_name = "mongoo-test"
16
+
17
+ You can set these on a model level as well:
18
+
19
+ Person.conn = Mongo::Connection.new("localhost", 30000, :pool_size => 5, :timeout => 5)
20
+ Person.db_name = "mongoo-test"
21
+
22
+
23
+ * You can optionally set the collection name on a model now:
24
+
25
+ class Person < Mongoo::Base
26
+ collection_name "spacemen"
27
+ end
28
+
29
+
30
+ * There is a new Identity Map feature available. It will only work when using find_one to
31
+ find a specific id. You need to manually turn it on:
32
+
33
+ Mongoo::IdentityMap.on!
34
+
35
+ If using it in a web application like Rails be sure to flush the map after each request:
36
+
37
+ Mongoo::IdentityMap.flush!
38
+
39
+ The map is scoped to the current thread or fiber. You can also turn the map back off:
40
+
41
+ Mongoo::IdentityMap.off!
42
+
43
+ Inspired by: http://railstips.org/blog/archives/2010/02/21/mongomapper-07-identity-map/
4
44
 
5
45
  == Contributing to mongoo
6
-
46
+
7
47
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
48
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
49
  * Fork the project
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -1,52 +1,63 @@
1
1
  module Mongoo
2
2
  class Cursor
3
3
  include Enumerable
4
-
4
+
5
5
  attr_accessor :mongo_cursor
6
6
 
7
7
  def initialize(obj_class, mongo_cursor)
8
8
  @obj_class = obj_class
9
9
  @mongo_cursor = mongo_cursor
10
10
  end
11
-
11
+
12
12
  def next_document
13
13
  if doc = @mongo_cursor.next_document
14
- @obj_class.new(doc, true)
14
+ obj = @obj_class.new(doc, true)
15
+ Mongoo::IdentityMap.write(obj) if Mongoo::IdentityMap.on?
16
+ obj
15
17
  end
16
18
  end
17
-
19
+
18
20
  alias :next :next_document
19
-
21
+
20
22
  def each
21
23
  @mongo_cursor.each do |doc|
22
- yield(@obj_class.new(doc, true))
24
+ obj = @obj_class.new(doc, true)
25
+ Mongoo::IdentityMap.write(obj) if Mongoo::IdentityMap.on?
26
+ yield obj
23
27
  end
24
28
  end
25
29
 
30
+ def to_a
31
+ arr = @mongo_cursor.to_a.collect { |doc| @obj_class.new(doc, true) }
32
+ if Mongoo::IdentityMap.on?
33
+ arr.each { |obj| Mongoo::IdentityMap.write(obj) }
34
+ end; arr
35
+ end
36
+
26
37
  def count
27
38
  @mongo_cursor.count
28
39
  end
29
-
40
+
30
41
  def sort(key_or_list, direction=nil)
31
42
  @mongo_cursor.sort(key_or_list, direction)
32
43
  self
33
44
  end
34
-
45
+
35
46
  def limit(number_to_return=nil)
36
47
  @mongo_cursor.limit(number_to_return)
37
48
  self
38
49
  end
39
-
50
+
40
51
  def skip(number_to_return=nil)
41
52
  @mongo_cursor.skip(number_to_return)
42
53
  self
43
54
  end
44
-
55
+
45
56
  def batch_size(size=0)
46
57
  @mongo_cursor.batch_size(size)
47
58
  self
48
59
  end
49
-
60
+
50
61
  def method_missing(name, *args)
51
62
  if @mongo_cursor.respond_to?(name)
52
63
  @mongo_cursor.send name, *args
@@ -54,6 +65,6 @@ module Mongoo
54
65
  super
55
66
  end
56
67
  end
57
-
68
+
58
69
  end
59
70
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoo}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
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"]
@@ -73,4 +73,45 @@ class TestIdentityMap < Test::Unit::TestCase
73
73
  Mongoo::IdentityMap.off!
74
74
  end
75
75
 
76
+ should "store results from find.to_a in map" do
77
+ p = Person.new("name" => "Ben")
78
+ p.insert!
79
+ Mongoo::IdentityMap.on!
80
+
81
+ people = Person.find.to_a
82
+ people[0].name = "Not Ben"
83
+
84
+ assert_equal "Not Ben", Person.find_one(p.id).name
85
+
86
+ Mongoo::IdentityMap.off!
87
+ end
88
+
89
+ should "store results from find.each in map" do
90
+ p = Person.new("name" => "Ben")
91
+ p.insert!
92
+ Mongoo::IdentityMap.on!
93
+
94
+ people = []
95
+ Person.find.each { |p| people << p }
96
+ people[0].name = "Not Ben"
97
+
98
+ assert_equal "Not Ben", Person.find_one(p.id).name
99
+
100
+ Mongoo::IdentityMap.off!
101
+ end
102
+
103
+ should "store results from find.next in map" do
104
+ p = Person.new("name" => "Ben")
105
+ p.insert!
106
+ Mongoo::IdentityMap.on!
107
+
108
+ people = []
109
+ people << Person.find.next
110
+
111
+ people[0].name = "Not Ben"
112
+
113
+ assert_equal "Not Ben", Person.find_one(p.id).name
114
+
115
+ Mongoo::IdentityMap.off!
116
+ end
76
117
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mongoo
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ben Myles
@@ -162,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
162
  requirements:
163
163
  - - ">="
164
164
  - !ruby/object:Gem::Version
165
- hash: -1099798970353591123
165
+ hash: 2078280549170362626
166
166
  segments:
167
167
  - 0
168
168
  version: "0"