Module: JustOneLock

Extended by:
Forwardable
Defined in:
lib/just_one_lock.rb,
lib/just_one_lock/version.rb

Defined Under Namespace

Classes: AlreadyLocked, BaseLocker, BlockingLocker, NonBlockingLocker, World

Constant Summary collapse

VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.prevent_multiple_executions(scope, locker = JustOneLock::NonBlockingLocker.new, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/just_one_lock.rb', line 20

def self.prevent_multiple_executions(
  scope,
  locker = JustOneLock::NonBlockingLocker.new,
  &block
)
  scope_name = scope.gsub(':', '_')
  lock_path = File.join(world.directory, scope_name + '.lock')

  begin
    return locker.lock(lock_path, &block)
  rescue JustOneLock::AlreadyLocked => e
    locker.already_locked(scope)
  end
end

.worldObject



16
17
18
# File 'lib/just_one_lock.rb', line 16

def self.world
  @world ||= JustOneLock::World.new
end