Sha256: 57b8b3319968c10af3f2b0424c7ac3f6856522c0759494c2a4ed7a33d275fc53
Contents?: true
Size: 1.63 KB
Versions: 3
Compression:
Stored size: 1.63 KB
Contents
require 'action_dispatch' module Rails module SessionCookie # This mini rack app allows easily get rails session cookie class App def self.simple_app_from_session_hash(session = {}) proc { |env| session.each do |k, v| env[RACK_SESSION][k] = v end [200, {}, []] } end def self.simple_app_returning_rack(app) proc { |env| result = app.call(env) result.is_a?(Hash) ? [200, result, []] : result } end attr_reader :app, :rails_app def initialize(app, session_options = nil) auth_session_options = session_options || rails_app.config.session_options auth_app = if app.respond_to?(:call) self.class.simple_app_returning_rack(app) else self.class.simple_app_from_session_hash(app) end @app = with_middlewares(auth_app, auth_session_options) end def call(env = {}) app.call(default_env.merge(env).dup) end def session_cookie(env = {}) _status, headers, _body = call(env) headers[ActionDispatch::Cookies::HTTP_HEADER] end private def with_middlewares(app, session_options) ActionDispatch::Cookies.new( ActionDispatch::Session::CookieStore.new( app, session_options ) ) end def default_env rails_app.env_config.merge('REQUEST_METHOD' => 'GET') end def rails_app @rails_app ||= defined?(Rails) && Rails.application || raise(NoRailsApplication) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rails-session_cookie-0.2.2 | lib/rails/session_cookie/app.rb |
rails-session_cookie-0.2.1 | lib/rails/session_cookie/app.rb |
rails-session_cookie-0.2.0 | lib/rails/session_cookie/app.rb |