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

MutexInfo =

The MutexInfo class is a subclass of OpenStruct, serving as a wrapper for information related to database mutexes. It allows dynamic attribute access.

Class.new OpenStruct
VERSION =

ActiveRecord::DatabaseMutex version

'3.2.0'
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) ⇒ ActiveRecord::DatabaseMutex::Implementation

The for method returns an instance of ActiveRecord::DatabaseMutex::Implementation that is initialized with the given name.

Parameters:

  • name (String)

    the mutex name

Returns:



51
52
53
# File 'lib/active_record/database_mutex.rb', line 51

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

.included(modul) ⇒ Object



38
39
40
41
42
# File 'lib/active_record/database_mutex.rb', line 38

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

Instance Method Details

#mutexActiveRecord::DatabaseMutex::Implementation

The mutex method returns an instance of ActiveRecord::DatabaseMutex::Implementation that is initialized with the name given by the id, the class and environment variables.

Returns:



89
90
91
92
93
94
95
# File 'lib/active_record/database_mutex.rb', line 89

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