mongodb-mongo 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,9 +30,9 @@ module XGen
30
30
  @name = name
31
31
  end
32
32
 
33
- # Set hint fields to use and return +self+. hint may be a
34
- # single field name, array of field names, or a hash whose keys will
35
- # become the hint field names. May be +nil+.
33
+ # Set hint fields to use and return +self+. hint may be a single field
34
+ # name, array of field names, or a hash (preferably an OrderedHash).
35
+ # May be +nil+.
36
36
  def hint=(hint)
37
37
  @hint = normalize_hint_fields(hint)
38
38
  self
@@ -59,7 +59,7 @@ module XGen
59
59
  if hint
60
60
  hint = normalize_hint_fields(hint)
61
61
  else
62
- hint = @hint
62
+ hint = @hint # assumed to be normalized already
63
63
  end
64
64
  raise RuntimeError, "Unknown options [#{options.inspect}]" unless options.empty?
65
65
  @db.query(self, Query.new(selector, fields, offset, limit, sort, hint))
@@ -157,13 +157,15 @@ module XGen
157
157
  def normalize_hint_fields(hint)
158
158
  case hint
159
159
  when String
160
- [hint]
160
+ {hint => 1}
161
161
  when Hash
162
- hint.keys
162
+ hint
163
163
  when nil
164
164
  nil
165
165
  else
166
- hint.to_a
166
+ h = OrderedHash.new
167
+ hint.to_a.each { |k| h[k] = 1 }
168
+ h
167
169
  end
168
170
  end
169
171
  end
@@ -44,14 +44,8 @@ module XGen
44
44
  raise "illegal order_by: is a #{query.order_by.class.name}, must be String, Array, Hash, or OrderedHash"
45
45
  end
46
46
  end
47
- if query.hint && query.hint.length > 0
48
- hints = OrderedHash.new
49
- query.hint.each { |hf| hints[hf] = 1 }
50
- sel['$hint'] = hints
51
- end
52
- if query.explain
53
- sel['$explain'] = true
54
- end
47
+ sel['$hint'] = query.hint if query.hint && query.hint.length > 0
48
+ sel['$explain'] = true if query.explain
55
49
 
56
50
  end
57
51
  write_doc(sel)
data/lib/mongo/query.rb CHANGED
@@ -28,7 +28,7 @@ module XGen
28
28
  attr_accessor :number_to_skip, :number_to_return, :order_by
29
29
  # If true, $explain will be set in QueryMessage that uses this query.
30
30
  attr_accessor :explain
31
- # Either +nil+ or an array of hint field names.
31
+ # Either +nil+ or a hash (preferably an OrderedHash).
32
32
  attr_accessor :hint
33
33
  attr_reader :selector # writer defined below
34
34
 
@@ -59,7 +59,8 @@ module XGen
59
59
  # is not preserved. (order_by is called :sort in calls to
60
60
  # Collection#find.)
61
61
  #
62
- # hint :: If not +nil+, specifies query hint fields. See
62
+ # hint :: If not +nil+, specifies query hint fields. Must be either
63
+ # +nil+ or a hash (preferably an OrderedHash). See
63
64
  # Collection#hint.
64
65
  def initialize(sel={}, return_fields=nil, number_to_skip=0, number_to_return=0, order_by=nil, hint=nil)
65
66
  @number_to_skip, @number_to_return, @order_by, @hint =
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mongo'
3
- s.version = '0.4.0'
3
+ s.version = '0.4.1'
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_db.rb CHANGED
@@ -123,4 +123,10 @@ class DBTest < Test::Unit::TestCase
123
123
  assert_equal err, err2
124
124
  end
125
125
 
126
+ def test_text_port_number
127
+ db = DB.new('ruby-mongo-test', [[@host, @port.to_s]])
128
+ # If there is no error, all is well
129
+ db.collection('users').clear
130
+ end
131
+
126
132
  end
data/tests/test_db_api.rb CHANGED
@@ -373,6 +373,7 @@ class DBAPITest < Test::Unit::TestCase
373
373
  end
374
374
 
375
375
  def test_hint
376
+ @coll.create_index('test_a_index', 'a')
376
377
  begin
377
378
  assert_nil @coll.hint
378
379
  assert_equal 1, @coll.find({'a' => 1}, :hint => 'a').to_a.size
@@ -380,15 +381,15 @@ class DBAPITest < Test::Unit::TestCase
380
381
  assert_equal 1, @coll.find({'a' => 1}, :hint => {'a' => 1}).to_a.size
381
382
 
382
383
  @coll.hint = 'a'
383
- assert_equal ['a'], @coll.hint
384
+ assert_equal({'a' => 1}, @coll.hint)
384
385
  assert_equal 1, @coll.find('a' => 1).to_a.size
385
386
 
386
387
  @coll.hint = ['a']
387
- assert_equal ['a'], @coll.hint
388
+ assert_equal({'a' => 1}, @coll.hint)
388
389
  assert_equal 1, @coll.find('a' => 1).to_a.size
389
390
 
390
391
  @coll.hint = {'a' => 1}
391
- assert_equal ['a'], @coll.hint
392
+ assert_equal({'a' => 1}, @coll.hint)
392
393
  assert_equal 1, @coll.find('a' => 1).to_a.size
393
394
 
394
395
  @coll.hint = nil
@@ -396,6 +397,8 @@ class DBAPITest < Test::Unit::TestCase
396
397
  assert_equal 1, @coll.find('a' => 1).to_a.size
397
398
  rescue => ex
398
399
  fail ex.to_s
400
+ ensure
401
+ @coll.drop_index('test_a_index')
399
402
  end
400
403
  end
401
404
 
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Menard