Sha256: 06c4028f63ea83a5400dc0c6208f3fd24994b5b736fdab3a41bcf7202979d26e

Contents?: true

Size: 544 Bytes

Versions: 4

Compression:

Stored size: 544 Bytes

Contents

class AccountMiddleware
  def initialize(app)
    @app = app
  end

  def call(env)
    request = ActionDispatch::Request.new(env)

    _, account_id, request_path = request.path.split("/", 3)

    if account_id !~ /\D/
      set_current_account(account_id)

      request.script_name = "/#{account_id}"
      request.path_info   = "/#{request_path}"
      @app.call(request.env)
    else
      @app.call(request.env)
    end
  end

  private
    def set_current_account(account_id)
      Current.account = Account.find(account_id)
    end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
authentication-zero-3.0.0.alpha1 lib/generators/authentication/templates/lib/account_middleware.rb
authentication-zero-2.16.36 lib/generators/authentication/templates/lib/account_middleware.rb
authentication-zero-2.16.35 lib/generators/authentication/templates/lib/account_middleware.rb
authentication-zero-2.16.34 lib/generators/authentication/templates/lib/account_middleware.rb