Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Added ability to have different serialize/deserialize methods for different scopes #48

Merged
merged 1 commit into from May 8, 2012

Conversation

Projects
None yet
2 participants

Tigraine commented May 8, 2012

Hi,
I ran across a requirement in my current application where I use Devise alongside a custom Warden implementation.

Devise is used to authenticate my admin users that are locally stored in the DB, while I also have to log in Visitors to the site that come from a different system using a Token based authentication.

Visitors and Admins are stored in different models and therefore I was struggling with Warden only having one deserialize method.

This pull request enables you to call Warden::Manager.serialize_into_session with a scope to supply a different method of serialization/deserialization for that special scope.

Example:

Warden::Manager.serialize_from_session(:admin) do |id|
  Visitor.find(id)
end

Warden::Manager.serialize_from_session do |id|
  User.find(id)
end

If no special scope deserializer/serializer has been given it still calls the serialize/deserialize methods as before.

I am a bit unhappy with my current implementation since I have to use respond_to? and send to test if that scoped_serialize is present and then retrieve it. I don't know how that kind of meta-programming impacts performance Ruby as I am fairly new to the language.

I hope the tests are in order, they are a bit messy and there are surely better ways to verify some of these methods but I didn't come up with anything better yesterday.

Feedback on how to improve this would be appreciated.

greetings Daniel

@Tigraine Daniel Hoelbling + Tigraine Added ability to have different serialize/deserialize methods for dif…
…ferent scopes.

Enables use-case where you store different Entities in different scopes (Like a Visitor and a AdminUser)
55bf091
Collaborator

josevalim commented May 8, 2012

Love this, merged.

@josevalim josevalim added a commit that referenced this pull request May 8, 2012

@josevalim josevalim Merge pull request #48 from Tigraine/scoped_session_store
Added ability to have different serialize/deserialize methods for different scopes
b2810b2

@josevalim josevalim merged commit b2810b2 into hassox:master May 8, 2012

Tigraine commented May 8, 2012

Wow that was quick.. awesome thanks!

@Tigraine Tigraine deleted the Tigraine:scoped_session_store branch Nov 13, 2013

@Tigraine Tigraine restored the Tigraine:scoped_session_store branch Nov 13, 2013

@Tigraine Tigraine deleted the Tigraine:scoped_session_store branch Nov 13, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment