module Sequel::Plugins::OptimisticLocking::InstanceMethods

Public Instance Methods

before_destroy() click to toggle source

Add the lock column instance filter to the object before destroying it.

Calls superclass method
# File lib/sequel/plugins/optimistic_locking.rb, line 44
def before_destroy
  lock_column_instance_filter
  super
end
before_update() click to toggle source

Add the lock column instance filter to the object before updating it.

Calls superclass method
# File lib/sequel/plugins/optimistic_locking.rb, line 50
def before_update
  lock_column_instance_filter
  super
end

Private Instance Methods

_refresh(ds) click to toggle source

Clear the instance filters when refreshing, so that attempting to refresh after a failed save removes the previous lock column filter (the new one will be added before updating).

Calls superclass method
# File lib/sequel/plugins/optimistic_locking.rb, line 66
def _refresh(ds)
  clear_instance_filters
  super
end
_update_columns(columns) click to toggle source

Only update the row if it has the same lock version, and increment the lock version.

Calls superclass method
# File lib/sequel/plugins/optimistic_locking.rb, line 73
def _update_columns(columns)
  lc = model.lock_column
  lcv = get_column_value(lc)
  columns[lc] = lcv + 1
  super
  set_column_value("#{lc}=", lcv + 1)
end
lock_column_instance_filter() click to toggle source

Add the lock column instance filter to the object.

# File lib/sequel/plugins/optimistic_locking.rb, line 58
def lock_column_instance_filter
  lc = model.lock_column
  instance_filter(lc=>get_column_value(lc))
end