module Rethinker::Document::Id
Public Class Methods
generate()
click to toggle source
TODO Unit test that thing
# File lib/rethinker/document/id.rb, line 38 def self.generate oid = '' # 4 bytes current time oid += [Time.now.to_i].pack("N") # 3 bytes machine oid += @machine_id # 2 bytes pid oid += [Process.pid % 0xFFFF].pack("n") # 3 bytes inc oid += [get_inc].pack("N")[1, 3] oid.unpack("C12").map {|e| v=e.to_s(16); v.size == 1 ? "0#{v}" : v }.join end
get_inc()
click to toggle source
# File lib/rethinker/document/id.rb, line 31 def self.get_inc @lock.synchronize do @index = (@index + 1) % 0xFFFFFF end end
Public Instance Methods
==(other)
click to toggle source
Calls superclass method
# File lib/rethinker/document/id.rb, line 17 def ==(other) return super unless self.class == other.class !id.nil? && id == other.id end
Also aliased as: eql?
reset_attributes()
click to toggle source
Calls superclass method
# File lib/rethinker/document/id.rb, line 12 def reset_attributes super self.id = Rethinker::Document::Id.generate end