Sha256: 3331a474db010d3d24f4c66f7117d0f34c9bdfaa5ccfef58b94746b5e9006c07

Contents?: true

Size: 1.18 KB

Versions: 67

Compression:

Stored size: 1.18 KB

Contents

module Authlogic
  module Session
    # 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.
    module PriorityRecord
      def self.included(klass)
        klass.class_eval do
          attr_accessor :priority_record
        end
      end
      
      # 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]
      def credentials=(value)
        super
        values = value.is_a?(Array) ? value : [value]
        self.priority_record = values[1] if values[1].class < ::ActiveRecord::Base
      end
      
      private
        def attempted_record=(value)
          value = priority_record if value == priority_record
          super
        end
        
        def save_record(alternate_record = nil)
          r = alternate_record || record
          super if r != priority_record
        end
    end
  end
end

Version data entries

67 entries across 67 versions & 21 rubygems

Version Path
authlogic-3.4.6 lib/authlogic/session/priority_record.rb
authlogic-3.4.5 lib/authlogic/session/priority_record.rb
authlogic-2.1.11 lib/authlogic/session/priority_record.rb
authlogic-2.1.10 lib/authlogic/session/priority_record.rb
authlogic-3.4.4 lib/authlogic/session/priority_record.rb
authlogic-3.4.3 lib/authlogic/session/priority_record.rb
binarylogic-authlogic-2.1.0 lib/authlogic/session/priority_record.rb
binarylogic-authlogic-2.1.1 lib/authlogic/session/priority_record.rb
crankharder-authlogic-2.1.1 lib/authlogic/session/priority_record.rb
jlecour-authlogic-2.1.2 lib/authlogic/session/priority_record.rb
kschrader-authlogic-2.1.2 lib/authlogic/session/priority_record.rb
kschrader-authlogic-2.1.3 lib/authlogic/session/priority_record.rb
authlogic-3.4.2 lib/authlogic/session/priority_record.rb
authlogic-3.4.1 lib/authlogic/session/priority_record.rb
authlogic-3.4.0 lib/authlogic/session/priority_record.rb
authlogic-3.3.0 lib/authlogic/session/priority_record.rb
authlogic-3.2.0 lib/authlogic/session/priority_record.rb
authlogic-3.1.3 lib/authlogic/session/priority_record.rb
authlogic-2.1.8 lib/authlogic/session/priority_record.rb
authlogic-2.1.7 lib/authlogic/session/priority_record.rb