Class: Rack::HalBrowser::Redirect

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Redirect.



9
10
11
12
13
# File 'lib/rack/hal_browser/redirect.rb', line 9

def initialize(app, options = {})
  @app = app
  @excluded_paths = Array(options[:exclude]) << "/hal-browser"
  @hal_browser = Rack::Static.new(@app, :urls => ["/hal-browser"], :root => ::File.expand_path("../../../../vendor", __FILE__))
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/rack/hal_browser/redirect.rb', line 15

def call(env)
  request = Rack::Request.new(env)
  if match?(request)
    return [303, {"Location" => hal_browser_url_from_request(request)}, []]
  end
  @hal_browser.call(env)
end