Created
August 12, 2012 22:37
-
-
Save bradpauly/3335006 to your computer and use it in GitHub Desktop.
simple file store for rails sessions
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
module ActionDispatch | |
module Session | |
class CustomFileStore < ActionDispatch::Session::AbstractStore | |
def get_session(env, session_id) | |
session_data = {} | |
session_id ||= generate_sid | |
File.open(tmp_file(session_id),'r') do |f| | |
data = f.read | |
session_data = ::Marshal.load(data) unless data.empty? | |
end rescue nil | |
[session_id, session_data] | |
end | |
def set_session(env, session_id, session_data, options) | |
File.open(tmp_file(session_id), 'w+') do |f| | |
encoded = ::Marshal.dump(session_data) | |
f.write(encoded) | |
end | |
session_id | |
end | |
def destroy_session(env, session_id, options) | |
File.unlink tmp_file(session_id) | |
generate_sid | |
end | |
def tmp_file(session_id) | |
File.join(Rails.root, 'tmp', 'sessions', session_id) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wrote a simple file store while I was researching rails sessions.