class Rutter::Mount

Represents a mounted app route.

@see Rutter::Route

@private

Public Class Methods

new(path, endpoint, constraints = nil, host: nil) click to toggle source

@see Rutter::Route#initialize

@private

Calls superclass method
# File lib/rutter/mount.rb, line 13
def initialize(path, endpoint, constraints = nil, host: nil)
  @host = host

  super(path, endpoint, constraints)
end

Public Instance Methods

match?(env) click to toggle source

Matches the app pattern against environment.

@param env [Hash]

Rack environment hash.

@return [nil, String]

Returns the matching substring or nil on no match.
# File lib/rutter/mount.rb, line 26
def match?(env)
  return if @host && !@host.match?(host(env))

  @pattern.peek(env["PATH_INFO"])
end

Private Instance Methods

host(env) click to toggle source

@private

# File lib/rutter/mount.rb, line 35
def host(env)
  env["rutter.parsed_host"] ||= begin
    if (forwarded = env["HTTP_X_FORWARDED_HOST"])
      forwarded.split(/,\s?/).last
    else
      env["HTTP_HOST"] || env["SERVER_NAME"] || env["SERVER_ADDR"]
    end
  end
end