Class: Vident::StableId

Inherits:
Object
  • Object
show all
Defined in:
lib/vident/stable_id.rb

Class Method Summary collapse

Class Method Details

.clear_current_sequence_generatorObject



19
20
21
# File 'lib/vident/stable_id.rb', line 19

def clear_current_sequence_generator
  ::Thread.current[:vident_number_sequence_generator] = nil
end

.next_id_in_sequenceObject



23
24
25
26
27
28
29
# File 'lib/vident/stable_id.rb', line 23

def next_id_in_sequence
  generator = ::Thread.current[:vident_number_sequence_generator]
  # When no generator exists, use a random value. This means we loose the stability of the ID sequence but
  # at least generate unique IDs for the current render.
  return Random.hex(16) unless generator
  generator.next.join("-")
end

.set_current_sequence_generatorObject Also known as: new_current_sequence_generator



14
15
16
# File 'lib/vident/stable_id.rb', line 14

def set_current_sequence_generator
  ::Thread.current[:vident_number_sequence_generator] = id_sequence_generator
end