Class: Fatalistic::Locker

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/fatalistic.rb

Overview

This class provides syntax abstraction for table locking. If this functionality is ever added to Active Record, the final code will end up looking much different: it’s currently set up with as much functionality outside AR as possible, in order to simplify testing and reduce dependencies.

Direct Known Subclasses

MySQLLocker, PostgresLocker

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_class) ⇒ Locker

Returns a new instance of Locker.



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

def initialize(model_class)
  @model_class = model_class
end

Instance Attribute Details

#model_classObject (readonly)

Returns the value of attribute model_class.



15
16
17
# File 'lib/fatalistic.rb', line 15

def model_class
  @model_class
end

Class Method Details

.for(model_class) ⇒ Object

Factory method to get an instance of the appropriate Locker subclass.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fatalistic.rb', line 19

def self.for(model_class)
  adapter_name = model_class.connection.adapter_name.downcase
  klass = if adapter_name.index("post")
    PostgresLocker
  elsif adapter_name.index("my")
    MySQLLocker
  else
    self
  end
  klass.new(model_class)
end

Instance Method Details

#lock(lock_statement = nil) ⇒ Object

Lock the table.



36
37
# File 'lib/fatalistic.rb', line 36

def lock(lock_statement = nil)
end

#unlockObject

Unlock the table. This is a no-op on all databases other than MySQL.



40
41
# File 'lib/fatalistic.rb', line 40

def unlock
end