Sha256: 57541fd9696f03226ac43648375366b4e2af7ded3d4d507dce6eef2871daac90
Contents?: true
Size: 982 Bytes
Versions: 10
Compression:
Stored size: 982 Bytes
Contents
#:enddoc: module RailsConnector class WorkspaceSelectionMiddleware CURRENT_WORKSPACE_SESSION_KEY = "infopark_rails_connector-current_workspace_id" CURRENT_WORKSPACE_PARAMS_KEY = "infopark_rails_connector-current_workspace_id" def initialize(app) @app = app end def call(env) handle_workspace_parameter(env) preview_workspace = session(env)[CURRENT_WORKSPACE_SESSION_KEY] Revision.current = proc do preview_workspace ? Revision.find(preview_workspace) : Revision.default end @app.call(env) end private def handle_workspace_parameter(env) workspace_id = Rack::Request.new(env).params[CURRENT_WORKSPACE_PARAMS_KEY] return unless workspace_id if workspace_id.present? session(env)[CURRENT_WORKSPACE_SESSION_KEY] = workspace_id else session(env).delete(CURRENT_WORKSPACE_SESSION_KEY) end end def session(env) env[Rack::Session::Abstract::ENV_SESSION_KEY] end end end # module RailsConnector
Version data entries
10 entries across 10 versions & 1 rubygems