Created
August 2, 2011 19:55
-
-
Save tiegz/1121054 to your computer and use it in GitHub Desktop.
Prioritize order of Authlogic::Session::Base persistence callbacks for Rails 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserSession < Authlogic::Session::Base | |
... # rest of your code | |
private | |
# Reorder persist_callback_chain at runtime (only way I know of doing this). | |
def run_callbacks(kind, options = {}, &block) | |
self.class.send("#{kind}_callback_chain").tap { |callback_chain| | |
if kind.to_s == "persist" | |
# Define the type of persistence methods | |
# This example "params" being first means that "persist_by_params" would fire first | |
[:params, :session, :http_auth, :cookie].reverse.each do |auth_method| | |
if index = callback_chain.map(&:method).index("persist_by_#{auth_method}".to_sym) | |
callback_chain.unshift(callback_chain.delete_at(index)) | |
end | |
end | |
end | |
}.run(self, options, &block) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment