Class: Utopia::Redirection::ClientRedirect
- Inherits:
-
Object
- Object
- Utopia::Redirection::ClientRedirect
show all
- Defined in:
- lib/utopia/redirection.rb
Overview
A basic client-side redirect.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(app, status: 307, max_age: DEFAULT_MAX_AGE) ⇒ ClientRedirect
Returns a new instance of ClientRedirect.
69
70
71
72
73
|
# File 'lib/utopia/redirection.rb', line 69
def initialize(app, status: 307, max_age: DEFAULT_MAX_AGE)
@app = app
@status = status
@max_age = max_age
end
|
Instance Attribute Details
#max_age ⇒ Object
Returns the value of attribute max_age.
85
86
87
|
# File 'lib/utopia/redirection.rb', line 85
def max_age
@max_age
end
|
#status ⇒ Object
Returns the value of attribute status.
84
85
86
|
# File 'lib/utopia/redirection.rb', line 84
def status
@status
end
|
Instance Method Details
#[](path) ⇒ Object
100
101
102
|
# File 'lib/utopia/redirection.rb', line 100
def [] path
false
end
|
#cache_control ⇒ Object
87
88
89
90
|
# File 'lib/utopia/redirection.rb', line 87
def cache_control
"max-age=#{self.max_age}"
end
|
#call(env) ⇒ Object
104
105
106
107
108
109
110
111
112
|
# File 'lib/utopia/redirection.rb', line 104
def call(env)
path = env[Rack::PATH_INFO]
if redirection = self[path]
return redirection
end
return @app.call(env)
end
|
#freeze ⇒ Object
75
76
77
78
79
80
81
82
|
# File 'lib/utopia/redirection.rb', line 75
def freeze
return self if frozen?
@status.freeze
@max_age.freeze
super
end
|
#redirect(location) ⇒ Object
96
97
98
|
# File 'lib/utopia/redirection.rb', line 96
def redirect(location)
return [self.status, self.(location), []]
end
|