Skip to content

Instantly share code, notes, and snippets.

@bradpauly
Created August 12, 2012 22:37
Show Gist options
  • Select an option

  • Save bradpauly/3335006 to your computer and use it in GitHub Desktop.

Select an option

Save bradpauly/3335006 to your computer and use it in GitHub Desktop.

Revisions

  1. bradpauly created this gist Aug 12, 2012.
    32 changes: 32 additions & 0 deletions custom_file_store.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    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