module ActiveRecord::Locking::Optimistic::ClassMethods

Constants

DEFAULT_LOCKING_COLUMN

Public Instance Methods

column_defaults() Show source
Calls superclass method
# File activerecord/lib/active_record/locking/optimistic.rb, line 172
def column_defaults
  @column_defaults ||= begin
    defaults = super

    if defaults.key?(locking_column) && lock_optimistically
      defaults[locking_column] ||= 0
    end

    defaults
  end
end
locking_column() Show source

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

# File activerecord/lib/active_record/locking/optimistic.rb, line 149
def locking_column
  reset_locking_column unless defined?(@locking_column)
  @locking_column
end
locking_column=(value) Show source

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

# File activerecord/lib/active_record/locking/optimistic.rb, line 143
def locking_column=(value)
  @column_defaults = nil
  @locking_column = value.to_s
end
locking_enabled?() Show source

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 activerecord/lib/active_record/locking/optimistic.rb, line 138
def locking_enabled?
  lock_optimistically && columns_hash[locking_column]
end
quoted_locking_column() Show source

Quote the column name used for optimistic locking.

# File activerecord/lib/active_record/locking/optimistic.rb, line 155
def quoted_locking_column
  ActiveSupport::Deprecation.warn "ActiveRecord::Base.quoted_locking_column is deprecated and will be removed in Rails 4.2 or later."
  connection.quote_column_name(locking_column)
end
reset_locking_column() Show source

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

# File activerecord/lib/active_record/locking/optimistic.rb, line 161
def reset_locking_column
  self.locking_column = DEFAULT_LOCKING_COLUMN
end
update_counters(id, counters) Show source

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

Calls superclass method
# File activerecord/lib/active_record/locking/optimistic.rb, line 167
def update_counters(id, counters)
  counters = counters.merge(locking_column => 1) if locking_enabled?
  super
end

© 2004–2016 David Heinemeier Hansson
Licensed under the MIT License.