Class: Reliable::UUID

Inherits:
Object
  • Object
show all
Defined in:
lib/reliable/uuid.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time, random = SecureRandom.uuid, tries = 0) {|_self| ... } ⇒ UUID

Returns a new instance of UUID.

Yields:

  • (_self)

Yield Parameters:



15
16
17
18
19
20
# File 'lib/reliable/uuid.rb', line 15

def initialize(time, random = SecureRandom.uuid, tries = 0)
  @time = time
  @random = random
  @tries = tries || 0
  yield(self) if block_given?
end

Instance Attribute Details

#randomObject (readonly)

Returns the value of attribute random.



13
14
15
# File 'lib/reliable/uuid.rb', line 13

def random
  @random
end

Class Method Details

.parse(key) ⇒ Object

Raises:



7
8
9
10
11
# File 'lib/reliable/uuid.rb', line 7

def self.parse(key)
  _, _, time, random, tries = key.split(":")
  raise MalformedUUID unless time && random && tries
  new(time, random, tries)
end

Instance Method Details

#incrObject



30
31
32
# File 'lib/reliable/uuid.rb', line 30

def incr
  @tries = tries + 1
end

#timeObject



22
23
24
# File 'lib/reliable/uuid.rb', line 22

def time
  @time.to_i
end

#to_sObject



34
35
36
# File 'lib/reliable/uuid.rb', line 34

def to_s
  "reliable:items:#{time}:#{random}:#{tries}"
end

#triesObject



26
27
28
# File 'lib/reliable/uuid.rb', line 26

def tries
  @tries.to_i
end