Class: Rack::WwwEnforcer

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/www-enforcer.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ WwwEnforcer

Returns a new instance of WwwEnforcer.



7
8
9
10
11
# File 'lib/rack/www-enforcer.rb', line 7

def initialize(app, options = {})
  @app = app
  @subdomain = options[:subdomain] || "www"
  @replace_subdomain = options[:replace_subdomain]
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/rack/www-enforcer.rb', line 13

def call(env)
  req = Request.new(env)
  if subdomain_present?(req)
    @app.call(env)
  else
    redirect_to_subdomain(req)
  end
end