Module: ActiveRecord::Locking::Optimistic::ClassMethods
- Defined in:
- activerecord/lib/active_record/locking/optimistic.rb
Constant Summary
- DEFAULT_LOCKING_COLUMN =
'lock_version'
Instance Method Summary (collapse)
-
- (Object) locking_column
The version column used for optimistic locking.
-
- (Boolean) locking_enabled?
Is optimistic locking enabled for this table? Returns true if the lock_optimistically flag is set to true (which it is, by default) and the table includes the locking_column column (defaults to lock_version).
-
- (Object) quoted_locking_column
Quote the column name used for optimistic locking.
-
- (Object) reset_locking_column
Reset the column used for optimistic locking back to the lock_version default.
-
- (Object) set_locking_column(value = nil, &block)
Set the column to use for optimistic locking.
-
- (Object) update_counters(id, counters)
Make sure the lock version column gets updated when counters are updated.
Instance Method Details
- (Object) locking_column
The version column used for optimistic locking. Defaults to lock_version.
149 150 151 |
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 149 def locking_column reset_locking_column end |
- (Boolean) locking_enabled?
Is optimistic locking enabled for this table? Returns true if the lock_optimistically flag is set to true (which it is, by default) and the table includes the locking_column column (defaults to lock_version).
138 139 140 |
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 138 def locking_enabled? lock_optimistically && columns_hash[locking_column] end |
- (Object) quoted_locking_column
Quote the column name used for optimistic locking.
154 155 156 |
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 154 def quoted_locking_column connection.quote_column_name(locking_column) end |
- (Object) reset_locking_column
Reset the column used for optimistic locking back to the lock_version default.
159 160 161 |
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 159 def reset_locking_column set_locking_column DEFAULT_LOCKING_COLUMN end |
- (Object) set_locking_column(value = nil, &block)
Set the column to use for optimistic locking. Defaults to lock_version.
143 144 145 146 |
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 143 def set_locking_column(value = nil, &block) define_attr_method :locking_column, value, &block value end |
- (Object) update_counters(id, counters)
Make sure the lock version column gets updated when counters are updated.
165 166 167 168 |
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 165 def update_counters(id, counters) counters = counters.merge(locking_column => 1) if locking_enabled? super end |