class Rack::TldLength

Public Class Methods

new(app, host_pattern, host_tld_length) click to toggle source
# File lib/rack/tld_length.rb, line 3
def initialize(app, host_pattern, host_tld_length)
  @app = app
  @host_pattern = Regexp.new(host_pattern)
  @host_tld_length = host_tld_length
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/tld_length.rb, line 9
def call(env)
  original_tld_length = tld_length

  request = Rack::Request.new(env)

  set_tld_length(@host_tld_length) if request.host =~ @host_pattern

  @app.call(env)
ensure
  set_tld_length(original_tld_length)
end

Private Instance Methods

set_tld_length(length) click to toggle source
# File lib/rack/tld_length.rb, line 26
def set_tld_length(length)
  ActionDispatch::Http::URL.tld_length = length
end
tld_length() click to toggle source
# File lib/rack/tld_length.rb, line 23
def tld_length
  ActionDispatch::Http::URL.tld_length
end