Sha256: 0b2e60fef84f27ada566fe66c8a134463a272edc3e3a21a669c0fa3ebbfea3de

Contents?: true

Size: 637 Bytes

Versions: 2

Compression:

Stored size: 637 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 identifier?(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 identifier?(value)
      Integer(value, exception: false) != nil
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
authentication-zero-2.16.33 lib/generators/authentication/templates/lib/account_middleware.rb
authentication-zero-2.16.32 lib/generators/authentication/templates/lib/account_middleware.rb