Sha256: 01e5bd8c986c17c87bb12c7193f64845a62f92f36904fd67230eca48fcb0c381

Contents?: true

Size: 628 Bytes

Versions: 2

Compression:

Stored size: 628 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 is_number?(account_id)
      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 is_number?(value)
      Integer(value, exception: false)
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
authentication-zero-2.16.31 lib/generators/authentication/templates/lib/account_middleware.rb
authentication-zero-2.16.30 lib/generators/authentication/templates/lib/account_middleware.rb