Class: BSON::ObjectId
- Inherits:
-
Object
- Object
- BSON::ObjectId
- Defined in:
- lib/yapper/bson.rb
Constant Summary collapse
- @@machine_id =
NSData.MD5HexDigest(UIDevice.currentDevice.identifierForVendor.UUIDString.dataUsingEncoding(NSUTF8StringEncoding)).unpack("N")[0]
- @@mutex =
Mutex.new
- @@counter =
0
Class Method Summary collapse
Class Method Details
.generate ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/yapper/bson.rb', line 8 def self.generate @@mutex.lock begin counter = @@counter = (@@counter + 1) % 0xFFFFFF ensure @@mutex.unlock rescue nil end process_thread_id = "#{Process.pid}#{Thread.current.object_id}".hash % 0xFFFF [Time.new.to_i, @@machine_id, process_thread_id, counter << 8].pack("N NX lXX NX").unpack("H*")[0] end |