em-mongo 0.4.0 → 0.4.1

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.0
1
+ 0.4.1
@@ -121,14 +121,14 @@ module EM::Mongo
121
121
  raise RuntimeError, "Unknown options [#{opts.inspect}]" unless opts.empty?
122
122
 
123
123
  EM::Mongo::Cursor.new(self, {
124
- :selector => selector,
125
- :fields => fields,
126
- :skip => skip,
124
+ :selector => selector,
125
+ :fields => fields,
126
+ :skip => skip,
127
127
  :limit => limit,
128
- :order => sort,
129
- :hint => hint,
130
- :snapshot => snapshot,
131
- :timeout => timeout,
128
+ :order => sort,
129
+ :hint => hint,
130
+ :snapshot => snapshot,
131
+ :timeout => timeout,
132
132
  :batch_size => batch_size,
133
133
  :transformer => transformer,
134
134
  :max_scan => max_scan,
@@ -142,8 +142,8 @@ module EM::Mongo
142
142
  # @return [EM::Mongo::RequestResponse]
143
143
  # calls back with a single document or nil if no result is found.
144
144
  #
145
- # @param [Hash, ObjectId, Nil] spec_or_object_id a hash specifying elements
146
- # which must be present for a document to be included in the result set or an
145
+ # @param [Hash, ObjectId, Nil] spec_or_object_id a hash specifying elements
146
+ # which must be present for a document to be included in the result set or an
147
147
  # instance of ObjectId to be used as the value for an _id query.
148
148
  # If nil, an empty selector, {}, will be used.
149
149
  #
@@ -256,7 +256,7 @@ module EM::Mongo
256
256
  # @option opts [Boolean] :upsert (+false+) if true, performs an upsert (update or insert)
257
257
  # @option opts [Boolean] :multi (+false+) update all documents matching the selector, as opposed to
258
258
  # just the first matching document. Note: only works in MongoDB 1.1.3 or later.
259
- # @option opts [Boolean] :safe (+true+)
259
+ # @option opts [Boolean] :safe (+true+)
260
260
  # If true, check that the save succeeded. OperationFailure
261
261
  # will be raised on an error. Note that a safe check requires an extra
262
262
  # round-trip to the database. Safe options provided here will override any safe
@@ -717,7 +717,7 @@ module EM::Mongo
717
717
  message.put_binary(BSON::BSON_CODER.serialize(doc, check_keys, true).to_s)
718
718
  end
719
719
  raise InvalidOperation, "Exceded maximum insert size of 16,000,000 bytes" if message.size > 16_000_000
720
-
720
+
721
721
  ids = documents.collect { |o| o[:_id] || o['_id'] }
722
722
 
723
723
  if safe_options[:safe]
@@ -773,12 +773,12 @@ module EM::Mongo
773
773
  if [EM::Mongo::ASCENDING, EM::Mongo::DESCENDING, EM::Mongo::GEO2D].include?(f[1])
774
774
  field_spec[f[0].to_s] = f[1]
775
775
  else
776
- raise MongoArgumentError, "Invalid index field #{f[1].inspect}; " +
776
+ raise MongoArgumentError, "Invalid index field #{f[1].inspect}; " +
777
777
  "should be one of Mongo::ASCENDING (1), Mongo::DESCENDING (-1) or Mongo::GEO2D ('2d')."
778
778
  end
779
779
  end
780
780
  else
781
- raise MongoArgumentError, "Invalid index specification #{spec.inspect}; " +
781
+ raise MongoArgumentError, "Invalid index specification #{spec.inspect}; " +
782
782
  "should be either a string, symbol, or an array of arrays."
783
783
  end
784
784
  field_spec
@@ -84,7 +84,7 @@ module EM::Mongo
84
84
  message.append!(last_error_message)
85
85
  last_error_id
86
86
  end
87
-
87
+
88
88
  def message_headers(operation, request_id, message)
89
89
  headers = BSON::ByteBuffer.new
90
90
  headers.put_int(16 + message.size)
@@ -264,7 +264,7 @@ module EM::Mongo
264
264
  def connected?
265
265
  @em_connection.connected?
266
266
  end
267
-
267
+
268
268
  def send_command(*args, &block);@em_connection.send_command(*args, &block);end
269
269
 
270
270
  # Is it okay to connect to a slave?
@@ -25,7 +25,7 @@ module EM::Mongo #:nodoc:
25
25
  DESCENDING_CONVERSION = ["descending", "desc", "-1"]
26
26
 
27
27
  # Converts the supplied +Array+ to a +Hash+ to pass to mongo as
28
- # sorting parameters. The returned +Hash+ will vary depending
28
+ # sorting parameters. The returned +Hash+ will vary depending
29
29
  # on whether the passed +Array+ is one or two dimensional.
30
30
  #
31
31
  # Example:
@@ -67,7 +67,7 @@ module EM::Mongo #:nodoc:
67
67
  { str => 1 }
68
68
  end
69
69
 
70
- # Converts the +String+, +Symbol+, or +Integer+ to the
70
+ # Converts the +String+, +Symbol+, or +Integer+ to the
71
71
  # corresponding sort value in MongoDB.
72
72
  #
73
73
  # Valid conversions (case-insensitive):
@@ -100,7 +100,7 @@ module EM::Mongo
100
100
  return response.succeed(nil) if doc.nil?
101
101
 
102
102
  if doc['$err']
103
-
103
+
104
104
  err = doc['$err']
105
105
 
106
106
  # If the server has stopped being the master (e.g., it's one of a
@@ -112,7 +112,7 @@ module EM::Mongo
112
112
  else
113
113
  response.fail([OperationFailure, err])
114
114
  end
115
-
115
+
116
116
  else
117
117
  response.succeed(
118
118
  @transformer ? @transformer.call(doc) : doc
@@ -180,7 +180,7 @@ module EM::Mongo
180
180
  # This method overrides any sort order specified in the Collection#find
181
181
  # method, and only the last sort applied has an effect.
182
182
  #
183
- # @param [Symbol, Array] key_or_list either 1) a key to sort by or 2)
183
+ # @param [Symbol, Array] key_or_list either 1) a key to sort by or 2)
184
184
  # an array of [key, direction] pairs to sort by. Direction should
185
185
  # be specified as EM::Mongo::ASCENDING (or :ascending / :asc) or EM::Mongo::DESCENDING (or :descending / :desc)
186
186
  #
@@ -308,10 +308,10 @@ module EM::Mongo
308
308
  elsif doc
309
309
  items << doc
310
310
  else
311
- response.succeed(items)
311
+ response.succeed(items)
312
312
  end
313
313
  end
314
- response
314
+ response
315
315
  end
316
316
 
317
317
  # Get the explain plan for this cursor.
@@ -322,7 +322,7 @@ module EM::Mongo
322
322
  def explain
323
323
  response = RequestResponse.new
324
324
  c = Cursor.new(@collection, query_options_hash.merge(:limit => -@limit.abs, :explain => true))
325
-
325
+
326
326
  exp_response = c.next_document
327
327
  exp_response.callback do |explanation|
328
328
  c.close
@@ -70,9 +70,10 @@ module EM::Mongo
70
70
  response = RequestResponse.new
71
71
  name_resp = collection_names
72
72
  name_resp.callback do |names|
73
- response.succeed names.map do |name|
73
+ collections = names.map do |name|
74
74
  EM::Mongo::Collection.new(@db_name, name, @em_connection)
75
75
  end
76
+ response.succeed collections
76
77
  end
77
78
  name_resp.errback { |err| response.fail err }
78
79
  response
@@ -177,7 +178,7 @@ module EM::Mongo
177
178
  oh[:index] = index_name.to_s
178
179
  cmd_resp = command(oh, :check_response => false)
179
180
  cmd_resp.callback do |doc|
180
- if EM::Mongo::Support.ok?(doc)
181
+ if EM::Mongo::Support.ok?(doc)
181
182
  response.succeed(true)
182
183
  else
183
184
  response.fail [MongoDBError, "Error with drop_index command: #{doc.inspect}"]
@@ -275,7 +276,7 @@ module EM::Mongo
275
276
  "#{name}.#{collection_name}"
276
277
  end
277
278
 
278
-
279
+
279
280
 
280
281
  # Send a command to the database.
281
282
  #
@@ -300,7 +301,7 @@ module EM::Mongo
300
301
  def command(selector, opts={})
301
302
  check_response = opts.fetch(:check_response, true)
302
303
  raise MongoArgumentError, "command must be given a selector" unless selector.is_a?(Hash) && !selector.empty?
303
-
304
+
304
305
  if selector.keys.length > 1 && RUBY_VERSION < '1.9' && selector.class != BSON::OrderedHash
305
306
  raise MongoArgumentError, "DB#command requires an OrderedHash when hash contains multiple keys"
306
307
  end
@@ -308,7 +309,7 @@ module EM::Mongo
308
309
  response = RequestResponse.new
309
310
  cmd_resp = Cursor.new(self.collection(SYSTEM_COMMAND_COLLECTION), :limit => -1, :selector => selector).next_document
310
311
 
311
- cmd_resp.callback do |doc|
312
+ cmd_resp.callback do |doc|
312
313
  if doc.nil?
313
314
  response.fail([OperationFailure, "Database command '#{selector.keys.first}' failed: returned null."])
314
315
  elsif (check_response && !EM::Mongo::Support.ok?(doc))
@@ -346,7 +347,7 @@ module EM::Mongo
346
347
  auth = BSON::OrderedHash.new
347
348
  auth['authenticate'] = 1
348
349
  auth['user'] = username
349
- auth['nonce'] = res['nonce']
350
+ auth['nonce'] = res['nonce']
350
351
  auth['key'] = EM::Mongo::Support.auth_key(username, password, res['nonce'])
351
352
 
352
353
  auth_resp2 = self.collection(SYSTEM_COMMAND_COLLECTION).first(auth)
@@ -31,4 +31,3 @@ module EM
31
31
  end
32
32
  end
33
33
 
34
-
@@ -1,7 +1,7 @@
1
1
  module EM::Mongo
2
2
  class ServerResponse
3
3
 
4
- attr_reader :size, :request_id, :response_to, :op,
4
+ attr_reader :size, :request_id, :response_to, :op,
5
5
  :result_flags, :cursor_id, :starting_from,
6
6
  :number_returned, :docs, :connection
7
7
 
@@ -27,6 +27,6 @@ module EM::Mongo
27
27
  BSON::BSON_CODER.deserialize(buf)
28
28
  end
29
29
  end
30
-
30
+
31
31
  end
32
32
  end
data/lib/em-mongo.rb CHANGED
@@ -9,9 +9,9 @@ module EM::Mongo
9
9
 
10
10
  module Version
11
11
  STRING = File.read(File.dirname(__FILE__) + '/../VERSION')
12
- MAJOR, MINOR, TINY = STRING.split('.')
12
+ MAJOR, MINOR, TINY = STRING.split('.')
13
13
  end
14
-
14
+
15
15
  NAME = 'em-mongo'
16
16
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
17
17
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
@@ -240,7 +240,7 @@ describe EMMongo::Collection do
240
240
  done
241
241
  end
242
242
  end
243
-
243
+
244
244
  it "should respond with an error when an invalid document is saved" do
245
245
  @conn, @coll = connection_and_collection('safe.test')
246
246
  @coll.create_index("hello", :unique => true)
@@ -285,8 +285,8 @@ describe EMMongo::Collection do
285
285
  @conn, @coll = connection_and_collection('safe.update.test')
286
286
  @coll.create_index("x", :unique => true)
287
287
  @coll.insert({"x" => 5})
288
- @coll.insert({"x" => 10})
289
-
288
+ @coll.insert({"x" => 10})
289
+
290
290
  @coll.safe_update({},{"x" => 10}).errback do |err|
291
291
  err[0].should == EM::Mongo::OperationFailure
292
292
  done
@@ -297,7 +297,7 @@ describe EMMongo::Collection do
297
297
  end
298
298
 
299
299
  describe "save" do
300
-
300
+
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)
@@ -325,8 +325,8 @@ describe EMMongo::Collection do
325
325
  @conn, @coll = connection_and_collection('safe.save.test')
326
326
  @coll.create_index("x", :unique => true)
327
327
  @coll.save({"x" => 5})
328
- @coll.save({"x" => 5})
329
-
328
+ @coll.save({"x" => 5})
329
+
330
330
  @coll.safe_save({"x" => 5}).errback do |err|
331
331
  err[0].should == EM::Mongo::OperationFailure
332
332
  done
@@ -363,7 +363,7 @@ describe EMMongo::Collection do
363
363
  end
364
364
 
365
365
  describe "find_and_modify" do
366
-
366
+
367
367
  it "should find and modify a document" do
368
368
  @conn, @coll = connection_and_collection
369
369
  @coll << { :a => 1, :processed => false }
@@ -448,7 +448,7 @@ describe EMMongo::Collection do
448
448
  res = @coll.map_reduce(m, r, :query => {"user_id" => {"$gt" => 1}}, :out => 'foo')
449
449
  res.callback do |collection|
450
450
  collection.count .callback do |c|
451
- c.should == 2
451
+ c.should == 2
452
452
  collection.find_one({"_id" => 2}).callback do |doc|
453
453
  doc.should_not be_nil
454
454
  collection.find_one({"_id" => 3}).callback do |doc2|
@@ -641,7 +641,7 @@ describe EMMongo::Collection do
641
641
  done
642
642
  end
643
643
  end
644
-
644
+
645
645
  it "should create a geospatial index" do
646
646
  @conn, @geo = connection_and_collection('geo')
647
647
  @geo.save({'loc' => [-100, 100]})
@@ -649,8 +649,8 @@ describe EMMongo::Collection do
649
649
  @geo.index_information.callback do |info|
650
650
  info['loc_2d'].should_not be_nil
651
651
  done
652
- end
653
- end
652
+ end
653
+ end
654
654
 
655
655
  it "should create a unique index" do
656
656
  @conn, @collection = connection_and_collection('test-collection')
@@ -722,21 +722,21 @@ describe EMMongo::Collection do
722
722
  done
723
723
  end
724
724
  end
725
-
725
+
726
726
  it "should drop an index" do
727
727
  @conn, @collection = connection_and_collection('test-collection')
728
728
  @collection.create_index([['a',EM::Mongo::ASCENDING]])
729
729
  @collection.index_information.callback do |info|
730
730
  info['a_1'].should_not be_nil
731
- @collection.drop_index([['a',EM::Mongo::ASCENDING]]).callback do
731
+ @collection.drop_index([['a',EM::Mongo::ASCENDING]]).callback do
732
732
  @collection.index_information.callback do |info|
733
733
  info['a_1'].should be_nil
734
734
  done
735
735
  end
736
736
  end
737
737
  end
738
-
739
- end
738
+
739
+ end
740
740
  end
741
741
 
742
742
  it 'should handle multiple pending queries' do
@@ -255,7 +255,7 @@ describe EMMongo::Cursor do
255
255
  cursor = EM::Mongo::Cursor.new(@coll).sort(["x", :desc])
256
256
  cursor.next_document.callback do |first|
257
257
  lambda { cursor.sort("x",1) }.should raise_error EM::Mongo::InvalidOperation
258
- done
258
+ done
259
259
  end
260
260
  end
261
261
 
@@ -267,7 +267,7 @@ describe EMMongo::Cursor do
267
267
  cursor = EM::Mongo::Cursor.new(@coll).sort(["x", :desc])
268
268
  cursor.next_document.callback do |first|
269
269
  first["x"].year.should == 2004
270
- done
270
+ done
271
271
  end
272
272
  end
273
273
 
@@ -7,7 +7,7 @@ describe EMMongo::Database do
7
7
  @conn = EM::Mongo::Connection.new
8
8
  @db = @conn.db
9
9
  @db.collection(EM::Mongo::Database::SYSTEM_USER_COLLECTION).remove({})
10
- @db.add_user('test', 'test').callback do |res|
10
+ @db.add_user('test', 'test').callback do |res|
11
11
  res.should_not == nil
12
12
  res.should be_a_kind_of(BSON::ObjectId)
13
13
  done
@@ -22,7 +22,7 @@ describe EMMongo::Database do
22
22
  res.should == true
23
23
  done
24
24
  end
25
- end
25
+ end
26
26
 
27
27
  it "should create a collection" do
28
28
  @conn = EM::Mongo::Connection.new
@@ -76,15 +76,15 @@ describe EMMongo::Database do
76
76
  end
77
77
  end
78
78
  end
79
-
79
+
80
80
  it 'should cache collections correctly' do
81
81
  @conn = EM::Mongo::Connection.new
82
82
  @db = @conn.db
83
83
  a = @db.collection('first_collection')
84
84
  b = @db.collection('second_collection')
85
- a.should_not == b
85
+ a.should_not == b
86
86
  @db.collection('first_collection').should == a
87
- @db.collection('second_collection').should == b
87
+ @db.collection('second_collection').should == b
88
88
  done
89
89
  end
90
90
 
@@ -94,7 +94,7 @@ describe EMMongo::Database do
94
94
  @conn = EM::Mongo::Connection.new
95
95
  @db = @conn.db
96
96
  @db.reset_error_history.callback do
97
- @db.get_last_error.callback do |doc|
97
+ @db.get_last_error.callback do |doc|
98
98
  doc['err'].should be_nil
99
99
  done
100
100
  end
@@ -116,7 +116,7 @@ describe EMMongo::Database do
116
116
  @conn = EM::Mongo::Connection.new
117
117
  @db = @conn.db
118
118
  @db.command({:forceerror=>1}, :check_response => false).callback do
119
- @db.get_last_error.callback do |doc|
119
+ @db.get_last_error.callback do |doc|
120
120
  doc['err'].should_not be_nil
121
121
  done
122
122
  end
@@ -23,7 +23,7 @@ describe EM::Mongo::RequestResponse do
23
23
  end
24
24
  context "when succeeded" do
25
25
  before(:each) { @response.succeed [:some,:data] }
26
-
26
+
27
27
  it "should have completed" do
28
28
  @response.completed?.should be_true
29
29
  end
@@ -37,8 +37,8 @@ describe EM::Mongo::RequestResponse do
37
37
  @response.data.should == [:some, :data]
38
38
  end
39
39
  it "should not have an error" do
40
- @response.error.should be_nil
41
- end
40
+ @response.error.should be_nil
41
+ end
42
42
  end
43
43
  context "when failed" do
44
44
  before(:each) { @response.fail [RuntimeError, "crap!"]}
@@ -56,8 +56,8 @@ describe EM::Mongo::RequestResponse do
56
56
  @response.data.should be_nil
57
57
  end
58
58
  it "should have an error" do
59
- @response.error.should == [RuntimeError, "crap!"]
60
- end
59
+ @response.error.should == [RuntimeError, "crap!"]
60
+ end
61
61
  end
62
62
 
63
63
  end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-mongo
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.4.0
4
+ hash: 13
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 4
9
+ - 1
10
+ version: 0.4.1
6
11
  platform: ruby
7
12
  authors:
8
13
  - bcg
@@ -11,7 +16,8 @@ autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
18
 
14
- date: 2010-12-01 00:00:00 Z
19
+ date: 2010-12-01 00:00:00 -05:00
20
+ default_executable:
15
21
  dependencies:
16
22
  - !ruby/object:Gem::Dependency
17
23
  name: eventmachine
@@ -21,6 +27,11 @@ dependencies:
21
27
  requirements:
22
28
  - - ">="
23
29
  - !ruby/object:Gem::Version
30
+ hash: 59
31
+ segments:
32
+ - 0
33
+ - 12
34
+ - 10
24
35
  version: 0.12.10
25
36
  type: :runtime
26
37
  version_requirements: *id001
@@ -32,6 +43,11 @@ dependencies:
32
43
  requirements:
33
44
  - - ">="
34
45
  - !ruby/object:Gem::Version
46
+ hash: 21
47
+ segments:
48
+ - 1
49
+ - 1
50
+ - 3
35
51
  version: 1.1.3
36
52
  type: :runtime
37
53
  version_requirements: *id002
@@ -43,6 +59,11 @@ dependencies:
43
59
  requirements:
44
60
  - - ">="
45
61
  - !ruby/object:Gem::Version
62
+ hash: 21
63
+ segments:
64
+ - 1
65
+ - 1
66
+ - 3
46
67
  version: 1.1.3
47
68
  type: :runtime
48
69
  version_requirements: *id003
@@ -73,6 +94,7 @@ files:
73
94
  - spec/integration/cursor_spec.rb
74
95
  - spec/integration/database_spec.rb
75
96
  - spec/integration/request_response_spec.rb
97
+ has_rdoc: true
76
98
  homepage: http://github.com/bcg/em-mongo
77
99
  licenses: []
78
100
 
@@ -86,17 +108,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
108
  requirements:
87
109
  - - ">="
88
110
  - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
89
114
  version: "0"
90
115
  required_rubygems_version: !ruby/object:Gem::Requirement
91
116
  none: false
92
117
  requirements:
93
118
  - - ">="
94
119
  - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
95
123
  version: "0"
96
124
  requirements: []
97
125
 
98
126
  rubyforge_project: em-mongo
99
- rubygems_version: 1.8.0
127
+ rubygems_version: 1.3.7
100
128
  signing_key:
101
129
  specification_version: 3
102
130
  summary: An EventMachine driver for MongoDB.