kongo 1.0.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/kongo.rb +11 -5
  2. data/lib/kongo/version.rb +1 -1
  3. metadata +2 -2
@@ -22,15 +22,21 @@ module Kongo
22
22
  end
23
23
  end
24
24
 
25
- # `find_one` and `find_by_id` are the same method. When passed a native
26
- # BSON::ObjectId, it will act as a find_by_id, otherwise, expects a regular
27
- # query hash. Will return a Kongo::Model.
25
+ # When passed a native BSON::ObjectId, it will act as a find_by_id,
26
+ # otherwise, expects a regular query hash. Will return a Kongo::Model.
28
27
  #
29
28
  def find_one(*args)
30
29
  (r = coll.find_one(*args)) ?
31
30
  Model.new(r, coll) : r
32
31
  end
33
- alias :find_by_id :find_one
32
+
33
+ # If passed a legal BSON ObjectId string, will convert to BSON::ObjectId.
34
+ # Otherwise finds by value.
35
+ #
36
+ def find_by_id(id)
37
+ id = BSON::ObjectId(id) if BSON::ObjectId.legal?(id)
38
+ find_one(_id: id)
39
+ end
34
40
 
35
41
  # `find`, aka. `find_many` returns a Kongo::Cursor wrapping the Mongo
36
42
  # cursor.
@@ -309,7 +315,7 @@ module Kongo
309
315
  # saved after an update has been issued.
310
316
  #
311
317
  def update!(deltas = {})
312
- return if @deltas.empty?
318
+ return if @deltas.empty? && deltas.empty?
313
319
 
314
320
  id = @hash['_id']
315
321
  raise unless id # TODO: custom exception
@@ -1,3 +1,3 @@
1
1
  module Kongo
2
- VERSION = '1.0.1'
2
+ VERSION = '1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: '1.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-11 00:00:00.000000000 Z
12
+ date: 2013-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongo