Class: Mementus::IntegerId

Inherits:
Object
  • Object
show all
Defined in:
lib/mementus/integer_id.rb

Instance Method Summary collapse

Constructor Details

#initialize(start_value = 1) ⇒ IntegerId

Returns a new instance of IntegerId.



5
6
7
8
# File 'lib/mementus/integer_id.rb', line 5

def initialize(start_value=1)
  @current_value = start_value
  @mutex = Mutex.new
end

Instance Method Details

#next_idObject



10
11
12
13
14
15
16
# File 'lib/mementus/integer_id.rb', line 10

def next_id
  @mutex.lock
  allocated = @current_value
  @current_value += 1
  @mutex.unlock
  allocated
end