Permalink
Browse files

use securerandom for _id on 1.8.7

  • Loading branch information...
1 parent 75028f7 commit 1325c942b2b05f560d988e857a80d9b895044638 @tmm1 committed Aug 24, 2008
Showing with 11 additions and 3 deletions.
  1. +0 −1 lib/mongo.rb
  2. +11 −2 lib/mongo/collection.rb
View
@@ -2,7 +2,6 @@
require 'ext/em'
require 'ext/fiber18'
require 'ext/emspec'
-require 'uuid'
module Mongo
class Error < Exception; end
@@ -1,3 +1,9 @@
+begin
+ require 'securerandom'
+rescue LoadError
+ require 'uuid'
+end
+
module Mongo
class Collection
@@ -38,8 +44,11 @@ def first *args
end
def insert obj
- obj[:_id] ||= UUID.new(:compact).gsub(/^(.{20})(.{8})(.{4})$/){ $1+$3 }
- p [:inserting, obj]
+ obj[:_id] ||= if defined? SecureRandom
+ SecureRandom.hex(12)
+ else
+ UUID.new(:compact).gsub(/^(.{20})(.{8})(.{4})$/){ $1+$3 }
+ end
@client.send 2002, :int, reserved = 0,
:cstring, @ns,

0 comments on commit 1325c94

Please sign in to comment.