mongodb-mongo 0.5.1 → 0.5.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/README.rdoc CHANGED
@@ -11,7 +11,8 @@ Start by reading the XGen::Mongo::Driver::Mongo and XGen::Mongo::Driver::DB
11
11
  documentation, then move on to XGen::Mongo::Driver::Collection and
12
12
  XGen::Mongo::Driver::Cursor.
13
13
 
14
- A quick code sample:
14
+ Here is a quick code sample. See the files in the "examples" subdirectory for
15
+ many more.
15
16
 
16
17
  require 'mongo'
17
18
 
@@ -49,17 +50,22 @@ you can install it as a gem from the source by typing
49
50
  $ rake gem:install
50
51
 
51
52
 
52
- = Demo
53
+ = Examples
53
54
 
54
- You can see and run the examples if you've downloaded the source. Mongo must
55
- be running, of course.
55
+ There are many examples in the "examples" subdirectory. Samples include using
56
+ the driver and using the GridFS class GridStore. Mongo must be running for
57
+ these examples to work, of course.
56
58
 
59
+ Here's how to start mongo and run the "simple.rb" example:
60
+
61
+ $ cd path/to/mongo
62
+ $ ./mongod run
63
+ ... then in another window ...
64
+ $ cd path/to/mongo-ruby-driver
57
65
  $ ruby examples/simple.rb
58
66
 
59
67
  See also the test code, especially tests/test_db_api.rb.
60
68
 
61
- For the GridFS class GridStore, see the tests.
62
-
63
69
 
64
70
  = The Driver
65
71
 
@@ -211,6 +217,18 @@ object or call the :strict= method:
211
217
 
212
218
  The method DB#strict? returns the current value of that flag.
213
219
 
220
+ == Cursors
221
+
222
+ Random cursor fun facts:
223
+
224
+ - Cursors are enumerable.
225
+
226
+ - The query doesn't get run until you actually attempt to retrieve data from a
227
+ cursor.
228
+
229
+ - Cursors have a to_a method.
230
+
231
+
214
232
 
215
233
  = Testing
216
234
 
@@ -8,7 +8,7 @@ host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
8
8
  port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
9
9
 
10
10
  puts "Connecting to #{host}:#{port}"
11
- db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-examples-complex')
11
+ db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-examples')
12
12
  coll = db.collection('test')
13
13
  coll.clear
14
14
 
@@ -1,6 +1,3 @@
1
- require "rubygems"
2
- require "benchwarmer"
3
-
4
1
  class Exception
5
2
  def errmsg
6
3
  "%s: %s\n%s" % [self.class, message, (backtrace || []).join("\n") << "\n"]
@@ -38,7 +35,7 @@ OBJS_COUNT = 100
38
35
 
39
36
  puts ">> Generating test data"
40
37
  msgs = %w{hola hello aloha ciao}
41
- arr = OBJS_COUNT.times.map {|x| { :number => x, :rndm => (rand(5)+1), :msg => msgs[rand(4)] }}
38
+ arr = (0...OBJS_COUNT).collect {|x| { :number => x, :rndm => (rand(5)+1), :msg => msgs[rand(4)] }}
42
39
  puts "generated"
43
40
 
44
41
  puts ">> Inserting data (#{arr.size})"
data/examples/simple.rb CHANGED
@@ -7,11 +7,17 @@ host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
7
7
  port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
8
8
 
9
9
  puts "Connecting to #{host}:#{port}"
10
- db = Mongo.new(host, port).db('ruby-mongo-examples-simple')
10
+ db = Mongo.new(host, port).db('ruby-mongo-examples')
11
11
  coll = db.collection('test')
12
+
13
+ # Erase all records from collection, if any
12
14
  coll.clear
13
15
 
16
+ # Insert 3 records
14
17
  3.times { |i| coll.insert({'a' => i+1}) }
15
18
 
16
19
  puts "There are #{coll.count()} records in the test collection. Here they are:"
17
20
  coll.find().each { |doc| puts doc.inspect }
21
+
22
+ # Destroy the collection
23
+ coll.drop
data/lib/mongo/admin.rb CHANGED
@@ -70,14 +70,15 @@ module XGen
70
70
  end
71
71
 
72
72
  # Validate a named collection by raising an exception if there is a
73
- # problem or returning +true+ if all is well.
73
+ # problem or returning an interesting hash (see especially the
74
+ # 'result' string value) if all is well.
74
75
  def validate_collection(name)
75
76
  doc = @db.db_command(:validate => name)
76
77
  raise "Error with validate command: #{doc.inspect}" unless @db.ok?(doc)
77
78
  result = doc['result']
78
79
  raise "Error with validation data: #{doc.inspect}" unless result.kind_of?(String)
79
80
  raise "Error: invalid collection #{name}: #{doc.inspect}" if result =~ /\b(exception|corrupt)\b/i
80
- true
81
+ doc
81
82
  end
82
83
 
83
84
  end
data/lib/mongo/cursor.rb CHANGED
@@ -42,13 +42,15 @@ module XGen
42
42
 
43
43
  def closed?; @closed; end
44
44
 
45
- # Return +true+ if there are more records to retrieve. We do not check
46
- # @num_to_return; #each is responsible for doing that.
45
+ # Internal method, not for general use. Return +true+ if there are
46
+ # more records to retrieve. We do not check @num_to_return; #each is
47
+ # responsible for doing that.
47
48
  def more?
48
49
  num_remaining > 0
49
50
  end
50
51
 
51
- # Return the next object. Raises an error if necessary.
52
+ # Return the next object or nil if there are no more. Raises an error
53
+ # if necessary.
52
54
  def next_object
53
55
  refill_via_get_more if num_remaining == 0
54
56
  o = @cache.shift
data/lib/mongo/db.rb CHANGED
@@ -288,8 +288,11 @@ module XGen
288
288
 
289
289
  # Close the connection to the database.
290
290
  def close
291
- @socket.close if @socket
292
- @socket = nil
291
+ if @socket
292
+ s = @socket
293
+ @socket = nil
294
+ s.close
295
+ end
293
296
  end
294
297
 
295
298
  def connected?
@@ -426,6 +429,7 @@ module XGen
426
429
  connect_to_master if !connected? && @auto_reconnect
427
430
  begin
428
431
  @socket.print(message.buf.to_s)
432
+ @socket.flush
429
433
  rescue => ex
430
434
  close
431
435
  raise ex
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mongo'
3
- s.version = '0.5.1'
3
+ s.version = '0.5.2'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.summary = 'Simple pure-Ruby driver for the 10gen Mongo DB'
6
6
  s.description = 'A pure-Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.'
data/tests/test_admin.rb CHANGED
@@ -54,7 +54,11 @@ class AdminTest < Test::Unit::TestCase
54
54
  end
55
55
 
56
56
  def test_validate_collection
57
- assert @admin.validate_collection(@coll.name)
57
+ doc = @admin.validate_collection(@coll.name)
58
+ assert_not_nil doc
59
+ result = doc['result']
60
+ assert_not_nil result
61
+ assert_match /firstExtent/, result
58
62
  end
59
63
 
60
64
  end
data/tests/test_db_api.rb CHANGED
@@ -405,4 +405,17 @@ class DBAPITest < Test::Unit::TestCase
405
405
  end
406
406
  end
407
407
 
408
+ # TODO this test fails with error message "Undefed Before end of object"
409
+ # That is a database error. The undefined type may go away.
410
+
411
+ # def test_insert_undefined
412
+ # doc = {'undef' => Undefined.new}
413
+ # @coll.clear
414
+ # @coll.insert(doc)
415
+ # p @db.error # DEBUG
416
+ # assert_equal 1, @coll.count
417
+ # row = @coll.find().next_object
418
+ # assert_not_nil row
419
+ # end
420
+
408
421
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongodb-mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Menard
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-11 00:00:00 -08:00
12
+ date: 2009-02-03 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15