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 = {}, &block) ⇒ 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 = {}, &block)
  @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