Sha256: f7e7a6f0a784ca8ef4b54bd008f7c74683d076f3d198dd7486a28b133293014b
Contents?: true
Size: 1.01 KB
Versions: 5
Compression:
Stored size: 1.01 KB
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) Workspace.current = workspace_to_show(env) @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 workspace_to_show(env) if preview_workspace = session(env)[CURRENT_WORKSPACE_SESSION_KEY] Workspace.find(preview_workspace) else Workspace.default end end def session(env) env[Rack::Session::Abstract::ENV_SESSION_KEY] end end end # module RailsConnector
Version data entries
5 entries across 5 versions & 1 rubygems