Class: WithTransactionalLock::Mixin::AdvisoryLockBase

Inherits:
Object
  • Object
show all
Defined in:
lib/with_transactional_lock/mixin.rb

Direct Known Subclasses

MySqlAdvisoryLock, PostgresAdvisoryLock

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, lock_name) ⇒ AdvisoryLockBase

Returns a new instance of AdvisoryLockBase.



37
38
39
40
# File 'lib/with_transactional_lock/mixin.rb', line 37

def initialize(connection, lock_name)
  @connection = connection
  @lock_name = lock_name
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



35
36
37
# File 'lib/with_transactional_lock/mixin.rb', line 35

def connection
  @connection
end

#lock_nameObject (readonly)

Returns the value of attribute lock_name.



35
36
37
# File 'lib/with_transactional_lock/mixin.rb', line 35

def lock_name
  @lock_name
end

Instance Method Details

#yield_with_lockObject



42
43
44
45
46
47
# File 'lib/with_transactional_lock/mixin.rb', line 42

def yield_with_lock
  connection.transaction do
    acquire_lock
    yield
  end
end