Module: ActiveRecord::DatabaseMutex

Defined in:
lib/active_record/database_mutex.rb,
lib/active_record/database_mutex/version.rb,
lib/active_record/database_mutex/implementation.rb

Overview

This module is mixed into ActiveRecord::Base to provide the mutex methods that return a mutex for a particular ActiveRecord::Base subclass/instance.

Defined Under Namespace

Modules: ClassMethods Classes: Implementation, MutexError, MutexInvalidState, MutexLocked, MutexSystemError, MutexUnlockFailed

Constant Summary collapse

VERSION =

ActiveRecord::DatabaseMutex version

'2.5.1'
VERSION_ARRAY =

:nodoc:

VERSION.split('.').map(&:to_i)
VERSION_MAJOR =

:nodoc:

VERSION_ARRAY[0]
VERSION_MINOR =

:nodoc:

VERSION_ARRAY[1]
VERSION_BUILD =

:nodoc:

VERSION_ARRAY[2]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(name) ⇒ Object

Return a mutex implementation for the mutex named name.



31
32
33
# File 'lib/active_record/database_mutex.rb', line 31

def self.for(name)
  Implementation.new(:name => name)
end

.included(modul) ⇒ Object



24
25
26
27
28
# File 'lib/active_record/database_mutex.rb', line 24

def self.included(modul)
  modul.instance_eval do
    extend ClassMethods
  end
end

Instance Method Details

#mutexObject

Returns a mutex instance for this ActiveRecord instance.



45
46
47
48
49
50
51
# File 'lib/active_record/database_mutex.rb', line 45

def mutex
  if persisted?
    @mutex ||= Implementation.new(:name => "#{id}@#{self.class.name}")
  else
    raise MutexInvalidState, "instance #{inspect} not persisted"
  end
end