em-mongo 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -154,7 +154,7 @@ module EM::Mongo
154
154
 
155
155
  def receive_data(data)
156
156
 
157
- @buffer.append!(BSON::ByteBuffer.new(data.unpack('C*')))
157
+ @buffer.append!(data)
158
158
 
159
159
  @buffer.rewind
160
160
  while message_received?(@buffer)
@@ -165,7 +165,7 @@ module EM::Mongo
165
165
 
166
166
  if @buffer.more?
167
167
  remaining_bytes= @buffer.size-@buffer.position
168
- @buffer = BSON::ByteBuffer.new(@buffer.get(remaining_bytes))
168
+ @buffer = BSON::ByteBuffer.new(@buffer.to_s[@buffer.position,remaining_bytes])
169
169
  @buffer.rewind
170
170
  else
171
171
  @buffer.clear
@@ -299,7 +299,7 @@ module EM::Mongo
299
299
  # efficient to retrieve documents as you need them by iterating over the cursor.
300
300
  #
301
301
  # @return [EM::Mongo::RequestResponse] Calls back with an array of documents.
302
- def to_a
302
+ def defer_as_a
303
303
  response = RequestResponse.new
304
304
  items = []
305
305
  self.each do |doc,err|
@@ -314,6 +314,9 @@ module EM::Mongo
314
314
  response
315
315
  end
316
316
 
317
+ # XXX to_a is confusing but we will leave it for now
318
+ alias to_a defer_as_a
319
+
317
320
  # Get the explain plan for this cursor.
318
321
  #
319
322
  # @return [EM::Mongo::RequestResponse] Calls back with a document containing the explain plan for this cursor.
@@ -534,4 +537,4 @@ module EM::Mongo
534
537
  end
535
538
  end
536
539
  end
537
- end
540
+ end
@@ -52,7 +52,7 @@ module EM::Mongo
52
52
  # @return [EM::Mongo::RequestResponse]
53
53
  def collection_names
54
54
  response = RequestResponse.new
55
- name_resp = collections_info.to_a
55
+ name_resp = collections_info.defer_as_a
56
56
  name_resp.callback do |docs|
57
57
  names = docs.collect{ |doc| doc['name'] || '' }
58
58
  names = names.delete_if {|name| name.index(self.name).nil? || name.index('$')}
@@ -200,7 +200,7 @@ module EM::Mongo
200
200
  def index_information(collection_name)
201
201
  response = RequestResponse.new
202
202
  sel = {:ns => full_collection_name(collection_name)}
203
- idx_resp = Cursor.new(self.collection(SYSTEM_INDEX_COLLECTION), :selector => sel).to_a
203
+ idx_resp = Cursor.new(self.collection(SYSTEM_INDEX_COLLECTION), :selector => sel).defer_as_a
204
204
  idx_resp.callback do |indexes|
205
205
  info = indexes.inject({}) do |info, index|
206
206
  info[index['name']] = index
data/lib/em-mongo/prev.rb CHANGED
@@ -6,7 +6,7 @@ module EM
6
6
  def find(selector={}, opts={}, &blk)
7
7
  raise "find requires a block" if not block_given?
8
8
 
9
- new_find(selector, opts).to_a.callback do |docs|
9
+ new_find(selector, opts).defer_as_a.callback do |docs|
10
10
  blk.call(docs)
11
11
  end
12
12
  end
@@ -38,7 +38,7 @@ module EM
38
38
 
39
39
  def find(collection_name, skip, limit, order, query, fields, &blk)
40
40
  db_name, col_name = db_and_col_name(collection_name)
41
- db(db_name).collection(col_name).find(query, :skip=>skip,:limit=>limit,:order=>order,:fields=>fields).to_a.callback do |docs|
41
+ db(db_name).collection(col_name).find(query, :skip=>skip,:limit=>limit,:order=>order,:fields=>fields).defer_as_a.callback do |docs|
42
42
  yield docs if block_given?
43
43
  end
44
44
  end
@@ -50,4 +50,4 @@ module EM
50
50
 
51
51
  end
52
52
  end
53
- end
53
+ end
@@ -21,12 +21,15 @@ module EM::Mongo
21
21
  @number_returned = buffer.get_int
22
22
 
23
23
  # Documents
24
- @docs = (1..number_returned).map do
24
+ pos = buffer.position
25
+ @docs = (1..@number_returned).map do
25
26
  size= @connection.peek_size(buffer)
26
- buf = buffer.get(size)
27
- BSON::BSON_CODER.deserialize(buf)
27
+ doc = BSON::BSON_CODER.deserialize(buffer.to_s[pos,size])
28
+ pos += size
29
+ buffer.position = pos
30
+ doc
28
31
  end
29
32
  end
30
33
 
31
34
  end
32
- end
35
+ end
@@ -32,7 +32,7 @@ describe EMMongo::Collection do
32
32
  @conn, @coll = connection_and_collection
33
33
 
34
34
  @coll.insert("hello" => 'world')
35
- @coll.find({"hello" => "world"},{}).to_a.callback do |res|
35
+ @coll.find({"hello" => "world"},{}).defer_as_a.callback do |res|
36
36
  res.size.should >= 1
37
37
  res[0]["hello"].should == "world"
38
38
  done
@@ -54,7 +54,7 @@ describe EMMongo::Collection do
54
54
  @conn, @coll = connection_and_collection
55
55
 
56
56
  @coll.insert('hello' => 'world')
57
- @coll.find({:hello => "world"},{}).to_a.callback do |res|
57
+ @coll.find({:hello => "world"},{}).defer_as_a.callback do |res|
58
58
  res.size.should >= 1
59
59
  res[0]["hello"].should == "world"
60
60
  done
@@ -65,7 +65,7 @@ describe EMMongo::Collection do
65
65
  @conn, @coll = connection_and_collection
66
66
 
67
67
  id = @coll.insert('hello' => 'world')
68
- @coll.find({:_id => id},{}).to_a.callback do |res|
68
+ @coll.find({:_id => id},{}).defer_as_a.callback do |res|
69
69
  res.size.should >= 1
70
70
  res[0]['hello'].should == "world"
71
71
  done
@@ -77,7 +77,7 @@ describe EMMongo::Collection do
77
77
 
78
78
  @coll.insert('one' => 'one')
79
79
  @coll.insert('two' => 'two')
80
- @coll.find.to_a.callback do |res|
80
+ @coll.find.defer_as_a.callback do |res|
81
81
  res.size.should >= 2
82
82
  done
83
83
  end
@@ -90,14 +90,14 @@ describe EMMongo::Collection do
90
90
  @coll.insert(:name => 'three', :position => 2)
91
91
  @coll.insert(:name => 'two', :position => 1)
92
92
 
93
- @coll.find({}, {:order => 'position'}).to_a.callback do |res|
93
+ @coll.find({}, {:order => 'position'}).defer_as_a.callback do |res|
94
94
  res[0]["name"].should == 'one'
95
95
  res[1]["name"].should == 'two'
96
96
  res[2]["name"].should == 'three'
97
97
  done
98
98
  end
99
99
 
100
- @coll.find({}, {:order => [:position, :desc]}).to_a.callback do |res|
100
+ @coll.find({}, {:order => [:position, :desc]}).defer_as_a.callback do |res|
101
101
  res[0]["name"].should == 'three'
102
102
  res[1]["name"].should == 'two'
103
103
  res[2]["name"].should == 'one'
@@ -141,7 +141,7 @@ describe EMMongo::Collection do
141
141
  @coll.insert({'num' => num, 'word' => word})
142
142
  end
143
143
 
144
- @coll.find({'num' => {'$in' => [1,3,5]}}).to_a.callback do |res|
144
+ @coll.find({'num' => {'$in' => [1,3,5]}}).defer_as_a.callback do |res|
145
145
  res.size.should == 3
146
146
  res.map{|r| r['num'] }.sort.should == [1,3,5]
147
147
  done
@@ -155,7 +155,7 @@ describe EMMongo::Collection do
155
155
  @coll.insert('num' => num, 'word' => word)
156
156
  end
157
157
 
158
- @coll.find({'num' => {'$gt' => 3}}).to_a.callback do |res|
158
+ @coll.find({'num' => {'$gt' => 3}}).defer_as_a.callback do |res|
159
159
  res.size.should == 6
160
160
  res.map{|r| r['num'] }.sort.should == [4,5,6,7,8,9]
161
161
  done
@@ -202,7 +202,7 @@ describe EMMongo::Collection do
202
202
 
203
203
  t = Time.now.utc.freeze
204
204
  @coll.insert('date' => t)
205
- @coll.find.to_a.callback do |res|
205
+ @coll.find.defer_as_a.callback do |res|
206
206
  res[0]['date'].to_s.should == t.to_s
207
207
  done
208
208
  end
@@ -222,7 +222,7 @@ describe EMMongo::Collection do
222
222
  'regex' => /abc$/ix
223
223
  }
224
224
  retobj = @coll.insert(obj)
225
- @coll.find({:_id => obj[:_id]}).to_a.callback do |ret|
225
+ @coll.find({:_id => obj[:_id]}).defer_as_a.callback do |ret|
226
226
  ret.size.should == 1
227
227
  ret[0].each_key do |key|
228
228
  next if key == '_id'
@@ -262,7 +262,7 @@ describe EMMongo::Collection do
262
262
 
263
263
  id = @coll.insert('hello' => 'world')
264
264
  @coll.update({'hello' => 'world'}, {'hello' => 'newworld'})
265
- @coll.find({:_id => id},{}).to_a.callback do |res|
265
+ @coll.find({:_id => id},{}).defer_as_a.callback do |res|
266
266
  res[0]['hello'].should == 'newworld'
267
267
  done
268
268
  end
@@ -273,7 +273,7 @@ describe EMMongo::Collection do
273
273
 
274
274
  id = @coll.insert('hello' => 'world')
275
275
  @coll.update({'hello' => 'world'}, {'$inc' => {'count' => 1}})
276
- @coll.find({:_id => id},{}).to_a.callback do |res|
276
+ @coll.find({:_id => id},{}).defer_as_a.callback do |res|
277
277
  res.first['hello'].should == 'world'
278
278
  res.first['count'].should == 1
279
279
  done
@@ -301,7 +301,7 @@ describe EMMongo::Collection do
301
301
  it "should insert a record when no id is present" do
302
302
  @conn, @coll = connection_and_collection
303
303
  id = @coll.save("x" => 1)
304
- @coll.find("x" => 1).to_a.callback do |result|
304
+ @coll.find("x" => 1).defer_as_a.callback do |result|
305
305
  result[0]["_id"].should == id
306
306
  done
307
307
  end
@@ -313,7 +313,7 @@ describe EMMongo::Collection do
313
313
  id = @coll.save(doc)
314
314
  doc["x"] = 2
315
315
  @coll.save(doc).should be_true
316
- @coll.find().to_a.callback do |result|
316
+ @coll.find().defer_as_a.callback do |result|
317
317
  result.count.should == 1
318
318
  result[0]["x"].should == 2
319
319
  done
@@ -342,7 +342,7 @@ describe EMMongo::Collection do
342
342
 
343
343
  id = @coll.insert('hello' => 'world')
344
344
  @coll.remove(:_id => id)
345
- @coll.find({'hello' => "world"}).to_a.callback do |res|
345
+ @coll.find({'hello' => "world"}).defer_as_a.callback do |res|
346
346
  res.size.should == 0
347
347
  done
348
348
  end
@@ -354,7 +354,7 @@ describe EMMongo::Collection do
354
354
  @coll.insert('one' => 'one')
355
355
  @coll.insert('two' => 'two')
356
356
  @coll.remove
357
- @coll.find.to_a.callback do |res|
357
+ @coll.find.defer_as_a.callback do |res|
358
358
  res.size.should == 0
359
359
  done
360
360
  end
@@ -34,7 +34,7 @@ describe EMMongo::Cursor do
34
34
  @coll.save(all[-1])
35
35
  end
36
36
 
37
- cursor.limit(5).skip(3).sort("x",1).to_a.callback do |results|
37
+ cursor.limit(5).skip(3).sort("x",1).defer_as_a.callback do |results|
38
38
  all.slice(3...8).each_with_index do |item,idx|
39
39
  results[idx]["x"].should == item["x"]
40
40
  end
@@ -49,7 +49,7 @@ describe EMMongo::Cursor do
49
49
  1501.times do |i|
50
50
  @coll.insert(i.to_s => i.to_s)
51
51
  end
52
- cursor.limit(1500).to_a.callback do |docs|
52
+ cursor.limit(1500).defer_as_a.callback do |docs|
53
53
  docs.length.should == 1500
54
54
  done
55
55
  end
@@ -80,12 +80,12 @@ describe EMMongo::Cursor do
80
80
  100.times do |i|
81
81
  @coll.save("x" => 1)
82
82
  end
83
- cursor.to_a.callback do |r1|
83
+ cursor.defer_as_a.callback do |r1|
84
84
  r1.length.should == 100
85
- cursor.to_a.callback do |r2|
85
+ cursor.defer_as_a.callback do |r2|
86
86
  r2.length.should == 0
87
87
  cursor.rewind!
88
- cursor.to_a.callback do |r3|
88
+ cursor.defer_as_a.callback do |r3|
89
89
  r3.length.should == 100
90
90
  done
91
91
  end
@@ -101,7 +101,7 @@ describe EMMongo::Cursor do
101
101
  1000.times do |i|
102
102
  @coll.save("x" => 1)
103
103
  end
104
- cursor.to_a.callback do |results|
104
+ cursor.defer_as_a.callback do |results|
105
105
  results.length.should == 1000
106
106
  done
107
107
  end
@@ -290,14 +290,14 @@ describe EMMongo::Cursor do
290
290
  end
291
291
  end
292
292
 
293
- describe "to_a" do
293
+ describe "defer_as_a" do
294
294
  it "should return an array of all documents in a query" do
295
295
  @conn, @coll = connection_and_collection
296
296
  5.times do |i|
297
297
  @coll.insert("x" => i)
298
298
  end
299
299
  cursor = EM::Mongo::Cursor.new(@coll).sort("x",1)
300
- cursor.to_a.callback do |docs|
300
+ cursor.defer_as_a.callback do |docs|
301
301
  docs.length.should == 5
302
302
  5.times do |i|
303
303
  docs[i]["x"].should == i
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-mongo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
4
+ prerelease:
5
+ version: 0.4.2
11
6
  platform: ruby
12
7
  authors:
13
8
  - bcg
@@ -16,8 +11,7 @@ autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
13
 
19
- date: 2010-12-01 00:00:00 -05:00
20
- default_executable:
14
+ date: 2010-12-01 00:00:00 Z
21
15
  dependencies:
22
16
  - !ruby/object:Gem::Dependency
23
17
  name: eventmachine
@@ -27,11 +21,6 @@ dependencies:
27
21
  requirements:
28
22
  - - ">="
29
23
  - !ruby/object:Gem::Version
30
- hash: 59
31
- segments:
32
- - 0
33
- - 12
34
- - 10
35
24
  version: 0.12.10
36
25
  type: :runtime
37
26
  version_requirements: *id001
@@ -43,30 +32,9 @@ dependencies:
43
32
  requirements:
44
33
  - - ">="
45
34
  - !ruby/object:Gem::Version
46
- hash: 21
47
- segments:
48
- - 1
49
- - 1
50
- - 3
51
35
  version: 1.1.3
52
36
  type: :runtime
53
37
  version_requirements: *id002
54
- - !ruby/object:Gem::Dependency
55
- name: bson_ext
56
- prerelease: false
57
- requirement: &id003 !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- hash: 21
63
- segments:
64
- - 1
65
- - 1
66
- - 3
67
- version: 1.1.3
68
- type: :runtime
69
- version_requirements: *id003
70
38
  description: EventMachine driver for MongoDB.
71
39
  email: brenden.grace@gmail.com
72
40
  executables: []
@@ -94,7 +62,6 @@ files:
94
62
  - spec/integration/cursor_spec.rb
95
63
  - spec/integration/database_spec.rb
96
64
  - spec/integration/request_response_spec.rb
97
- has_rdoc: true
98
65
  homepage: http://github.com/bcg/em-mongo
99
66
  licenses: []
100
67
 
@@ -108,23 +75,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
75
  requirements:
109
76
  - - ">="
110
77
  - !ruby/object:Gem::Version
111
- hash: 3
112
- segments:
113
- - 0
114
78
  version: "0"
115
79
  required_rubygems_version: !ruby/object:Gem::Requirement
116
80
  none: false
117
81
  requirements:
118
82
  - - ">="
119
83
  - !ruby/object:Gem::Version
120
- hash: 3
121
- segments:
122
- - 0
123
84
  version: "0"
124
85
  requirements: []
125
86
 
126
87
  rubyforge_project: em-mongo
127
- rubygems_version: 1.3.7
88
+ rubygems_version: 1.8.11
128
89
  signing_key:
129
90
  specification_version: 3
130
91
  summary: An EventMachine driver for MongoDB.