Class: Flatrack::Redirector::Redirect
- Inherits:
-
Object
- Object
- Flatrack::Redirector::Redirect
- Defined in:
- lib/flatrack/redirector.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#code ⇒ Object
Returns the code for the specified type.
-
#initialize(url, type = :permanent) ⇒ Redirect
constructor
A new instance of Redirect.
- #response ⇒ Object
Constructor Details
#initialize(url, type = :permanent) ⇒ Redirect
Returns a new instance of Redirect.
38 39 40 41 |
# File 'lib/flatrack/redirector.rb', line 38 def initialize(url, type = :permanent) @url, @type = url, type code # just to check args end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
36 37 38 |
# File 'lib/flatrack/redirector.rb', line 36 def type @type end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
36 37 38 |
# File 'lib/flatrack/redirector.rb', line 36 def url @url end |
Instance Method Details
#code ⇒ Object
Returns the code for the specified type
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/flatrack/redirector.rb', line 45 def code case type.to_sym when :permanent 301 when :temporary 302 else raise ArgumentError, 'type must be :temporary or :permanent' end end |
#response ⇒ Object
56 57 58 |
# File 'lib/flatrack/redirector.rb', line 56 def response [code, { 'location' => url }, ["you are being redirected to: `#{url}`"]] end |