Class: Fatalistic::Locker
- Inherits:
-
Object
- Object
- Fatalistic::Locker
- 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
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
Class Method Summary collapse
-
.for(model_class) ⇒ Object
Factory method to get an instance of the appropriate Locker subclass.
Instance Method Summary collapse
-
#initialize(model_class) ⇒ Locker
constructor
A new instance of Locker.
-
#lock(lock_statement = nil) ⇒ Object
Lock the table.
-
#unlock ⇒ Object
Unlock the table.
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_class ⇒ Object (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 |
#unlock ⇒ Object
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 |