Class: Usher::Interface::Rack::Route

Inherits:
Route
  • Object
show all
Defined in:
lib/usher/interface/rack/route.rb

Overview

Route specific for Rack with redirection support built in.

Instance Attribute Summary

Attributes inherited from Route

#conditions, #default_values, #destination, #generate_with, #grapher, #match_partially, #named, #original_path, #parent_route, #paths, #priority, #recognizable, #requirements, #router

Instance Method Summary collapse

Methods inherited from Route

#destination_keys, #dup, #find_matching_path, #initialize, #inspect, #match_partially!, #name, #recognizable!, #recognizable?, #to, #to_s, #unrecognizable!

Constructor Details

This class inherits a constructor from Usher::Route

Instance Method Details

#redirect(path, status = 302) ⇒ Object

Redirect route to some other path.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/usher/interface/rack/route.rb', line 8

def redirect(path, status = 302)
  unless (300..399).include?(status)
    raise ArgumentError, "Status has to be an integer between 300 and 399"
  end
  to { |env|
    params = env[Usher::Interface::Rack::ENV_KEY_PARAMS]
    response = ::Rack::Response.new
    response.redirect(eval(%|"#{path}"|), status)
    response.finish
  }
  self
end

#serves_static_from(root) ⇒ Object



21
22
23
24
# File 'lib/usher/interface/rack/route.rb', line 21

def serves_static_from(root)
  match_partially!
  @destination = ::Rack::File.new(root)
end