@@ -39,9 +39,10 @@ module Session
39
39
# feature-packed Active Record or a bare-metal high-performance SQL
40
40
# store, by setting
41
41
#
42
- # ActionDispatch::Session::ActiveRecordStore.session_class = MySessionClass
42
+ # ActionDispatch::Session::ActiveRecordStore.session_class = " MySessionClass"
43
43
#
44
- # You must implement these methods:
44
+ # The class may optionally be passed as a string or proc to prevent autoloading
45
+ # code early. You must implement these methods:
45
46
#
46
47
# self.find_by_session_id(session_id)
47
48
# initialize(hash_of_session_id_and_data, options_hash = {})
@@ -53,13 +54,33 @@ module Session
53
54
# The example SqlBypass class is a generic SQL session store. You may
54
55
# use it as a basis for high-performance database-specific stores.
55
56
class ActiveRecordStore < ActionDispatch ::Session ::AbstractSecureStore
56
- # The class used for session storage. Defaults to
57
- # ActiveRecord::SessionStore::Session
58
- class_attribute :session_class
57
+ class << self
58
+ # The class used for session storage. Defaults to
59
+ # ActiveRecord::SessionStore::Session
60
+ def session_class
61
+ @session_class_instance ||= case @session_class
62
+ when Proc
63
+ @session_class . call
64
+ when String
65
+ @session_class . constantize
66
+ else
67
+ @session_class
68
+ end
69
+ end
70
+
71
+ def session_class = ( session_class )
72
+ @session_class_instance = nil
73
+ @session_class = session_class
74
+ end
75
+ end
59
76
60
77
SESSION_RECORD_KEY = 'rack.session.record'
61
78
ENV_SESSION_OPTIONS_KEY = Rack ::RACK_SESSION_OPTIONS
62
79
80
+ def session_class
81
+ self . class . session_class
82
+ end
83
+
63
84
private
64
85
def get_session ( request , sid )
65
86
logger . silence do
0 commit comments