Files

Class/Module Index [+]

Quicksearch

ActiveRecord::Locking::Optimistic::ClassMethods

Public Class Methods

extended(base) click to toggle source
# File lib/active_record/locking/optimistic.rb, line 138
def self.extended(base)
  class <<base
    alias_method_chain :update_counters, :lock
  end
end

Public Instance Methods

locking_column() click to toggle source

The version column used for optimistic locking. Defaults to lock_version.

# File lib/active_record/locking/optimistic.rb, line 159
def locking_column
  reset_locking_column
end
locking_enabled?() click to toggle source

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).

# File lib/active_record/locking/optimistic.rb, line 148
def locking_enabled?
  lock_optimistically && columns_hash[locking_column]
end
quoted_locking_column() click to toggle source

Quote the column name used for optimistic locking.

# File lib/active_record/locking/optimistic.rb, line 164
def quoted_locking_column
  connection.quote_column_name(locking_column)
end
reset_locking_column() click to toggle source

Reset the column used for optimistic locking back to the lock_version default.

# File lib/active_record/locking/optimistic.rb, line 169
def reset_locking_column
  set_locking_column DEFAULT_LOCKING_COLUMN
end
set_locking_column(value = nil, &block) click to toggle source

Set the column to use for optimistic locking. Defaults to lock_version.

# File lib/active_record/locking/optimistic.rb, line 153
def set_locking_column(value = nil, &block)
  define_attr_method :locking_column, value, &block
  value
end
update_counters_with_lock(id, counters) click to toggle source

Make sure the lock version column gets updated when counters are updated.

# File lib/active_record/locking/optimistic.rb, line 175
def update_counters_with_lock(id, counters)
  counters = counters.merge(locking_column => 1) if locking_enabled?
  update_counters_without_lock(id, counters)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.