Sha256: 49a711c308289ff29d973dfd879d0bbb1465c5c0ddfdac0c6f9d74c83296e6e5

Contents?: true

Size: 1.16 KB

Versions: 14

Compression:

Stored size: 1.16 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

14 entries across 14 versions & 1 rubygems

Version Path
refinerycms-0.9.6.34 vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb
refinerycms-0.9.6.33 vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb
refinerycms-0.9.6.32 vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb
refinerycms-0.9.6.31 vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb
refinerycms-0.9.6.30 vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb
refinerycms-0.9.6.29 vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb
refinerycms-0.9.6.28 vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb
refinerycms-0.9.6.27 vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb
refinerycms-0.9.6.26 vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb
refinerycms-0.9.6.25 vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb
refinerycms-0.9.6.24 vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb
refinerycms-0.9.6.23 vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb
refinerycms-0.9.6.22 vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb
refinerycms-0.9.6.21 vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb