Class: Rack::Bouncer

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/bouncer.rb

Constant Summary collapse

VERSION =
"1.4.2"
DEFAULT_OPTIONS =
{
  :safe_paths      => [],
  :redirect        => "http://browsehappy.com/",
  :minimum_chrome  => 7.0,
  :minimum_firefox => 4.0,
  :minimum_ie      => 8.0,
  :minimum_safari  => 4.0
}

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Bouncer.



16
17
18
19
# File 'lib/rack/bouncer.rb', line 16

def initialize(app, options = {})
  @app     = app
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Method Details

#call(env) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rack/bouncer.rb', line 21

def call(env)
  path_info  = env["PATH_INFO"]
  user_agent = env["HTTP_USER_AGENT"]

  return @app.call(env) if safe_path?(path_info) || user_agent_blank?(user_agent)

  return expel if undesirable_ie?(user_agent)      ||
                  undesirable_aol?(user_agent)     ||
                  undesirable_firefox?(user_agent) ||
                  undesirable_safari?(user_agent)  ||
                  undesirable_chrome?(user_agent)

  @app.call(env)
end