Class: Flatrack::Redirector::Redirect

Inherits:
Object
  • Object
show all
Defined in:
lib/flatrack/redirector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#typeObject (readonly)

Returns the value of attribute type.



36
37
38
# File 'lib/flatrack/redirector.rb', line 36

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url.



36
37
38
# File 'lib/flatrack/redirector.rb', line 36

def url
  @url
end

Instance Method Details

#codeObject

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

#responseObject



56
57
58
# File 'lib/flatrack/redirector.rb', line 56

def response
  [code, { 'location' => url }, ["you are being redirected to: `#{url}`"]]
end