-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow subclasses of session store to override session_class #204
Allow subclasses of session store to override session_class #204
Conversation
@@ -67,7 +67,7 @@ def get_session(request, sid) | |||
# If the sid was nil or if there is no pre-existing session under the sid, | |||
# force the generation of a new sid and associate a new session associated with the new sid | |||
sid = generate_sid | |||
session = @@session_class.new(:session_id => sid.private_id, :data => {}) | |||
session = session_class.new(:session_id => sid.private_id, :data => {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
session_class
is a cattr_accessor
, meaning subclasses will fight over that variable. You want class_attribute
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cattr_accessor actually generates https://apidock.com/rails/Class/cattr_accessor but agreed, I will change it to self.class.session_class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cattr_accessor actually generates
That's not the problem, the problem is that it is backed by a class variable (@@
) https://github.com/rails/rails/blob/522c86f35ccc80453ed9fb6ca8b394db321f9a69/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb#L124
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated it
I didn't mean to chance for self.class....
calls, but to declare the variable with class_attribute
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, never ran across class_attribute
before
With the current implementation it is not possible for different subclasses to use different session models since it uses a class variable to access it which is shared amongst inherited classes. This uses the accessor method instead which can be overriden by subclasses
With the current implementation it is not possible for different subclasses to use different session models since it uses a class variable to access it which is shared amongst inherited classes.
This changes uses the accessor method instead which can be overridden by the subclass(es).
This includes the changes from #194 to make the pipeline work again