lib/rails_warden.rb in rails_warden-0.2.5 vs lib/rails_warden.rb in rails_warden-0.2.6
- old
+ new
@@ -51,22 +51,21 @@
include RailsWarden::Mixins::HelperMethods
end
end
end
-# Session Serialization in. This block determines how the user will
-# be stored in the session. If you're using a complex object like an
-# ActiveRecord model, it is not a good idea to store the complete object.
-# An ID is sufficient
-Warden::Manager.serialize_into_session{ |user| [user.class, user.id] }
+class Warden::Serializers::Session
+ def serialize(user)
+ [user.class, user.id]
+ end
-# Session Serialization out. This block gets the user out of the session.
-# It should be the reverse of serializing the object into the session
-Warden::Manager.serialize_from_session do |klass, id|
- klass = case klass
- when Class
- klass
- when String, Symbol
- klass.to_s.classify.constantize
+ def deserialize(key)
+ klass, id = key
+ klass = case klass
+ when Class
+ klass
+ when String, Symbol
+ klass.to_s.classify.constantize
+ end
+ klass.find(id)
end
- klass.find(id)
end