module Authlogic::Session::PriorityRecord

The point of this module is to avoid the StaleObjectError raised when lock_version is implemented in ActiveRecord. We accomplish this by using a “priority record”. Meaning this record is used if possible, it gets priority. This way we don't save a record behind the scenes thus making an object being used stale.

Public Class Methods

included(klass) click to toggle source
# File lib/authlogic/session/priority_record.rb, line 7
def self.included(klass)
  klass.class_eval do
    attr_accessor :priority_record
  end
end

Public Instance Methods

credentials=(value) click to toggle source

Setting priority record if it is passed. The only way it can be passed is through an array:

session.credentials = [real_user_object, priority_user_object]
Calls superclass method
# File lib/authlogic/session/priority_record.rb, line 16
def credentials=(value)
  super
  values = value.is_a?(Array) ? value : [value]
  self.priority_record = values[1] if values[1].class < ::ActiveRecord::Base
end

Private Instance Methods

attempted_record=(value) click to toggle source
Calls superclass method
# File lib/authlogic/session/priority_record.rb, line 23
def attempted_record=(value)
  value = priority_record if value == priority_record
  super
end
save_record(alternate_record = nil) click to toggle source
Calls superclass method
# File lib/authlogic/session/priority_record.rb, line 28
def save_record(alternate_record = nil)
  r = alternate_record || record
  super if r != priority_record
end