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

Version Path
infopark_cloud_connector-6.8.0.72.d18d096 lib/rails_connector/workspace_selection_middleware.rb
infopark_cloud_connector-6.8.0.23.da7f96b lib/rails_connector/workspace_selection_middleware.rb
infopark_cloud_connector-6.8.0.16.def5e85 lib/rails_connector/workspace_selection_middleware.rb
infopark_cloud_connector-6.8.0.15.a24f5ff lib/rails_connector/workspace_selection_middleware.rb
infopark_cloud_connector-6.8.0.beta.200.891.647580e lib/rails_connector/workspace_selection_middleware.rb
infopark_cloud_connector-6.8.0.beta.200.889.d503e42 lib/rails_connector/workspace_selection_middleware.rb
infopark_cloud_connector-6.8.0.beta.200.883.f5f063b lib/rails_connector/workspace_selection_middleware.rb
infopark_cloud_connector-6.8.0.beta.200.884.4bd86e6 lib/rails_connector/workspace_selection_middleware.rb
infopark_cloud_connector-6.8.0.beta.200.869.9609b39 lib/rails_connector/workspace_selection_middleware.rb
infopark_cloud_connector-6.8.0.beta.200.856.8c0fec5 lib/rails_connector/workspace_selection_middleware.rb