Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 9bec2d5993
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 42 lines (36 sloc) 0.982 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
require 'dm-core'
require 'rack_datamapper/session/datamapper'
begin
  require 'securerandom'
rescue LoadError
end

module ActionController
  module Session
    class DatamapperStore < AbstractStore
      SecureRandom =
        if defined?(::SecureRandom)
          # Use Ruby's SecureRandom library if available.
          ::SecureRandom
        else
          # try if there is active support around ;-)
          require 'active_support'
          ::ActiveSupport::SecureRandom
        end

      def initialize(app, options = {})
        super

        id_generator = Proc.new do
          SecureRandom.hex(16)
        end
        @store = ::DataMapper::Session::Abstract::Store.new(app, options, id_generator)
        @options = options
      end

      private
      def get_session(env, sid)
        @store.get_session(env, sid)
      end

      def set_session(env, sid, session_data)
        @store.set_session(env, sid, session_data, @options)
      end
    end
  end
end
Something went wrong with that request. Please try again.