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
86
87
88
89
90
|
# File 'lib/utopia/redirection.rb', line 86
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
102
103
104
|
# File 'lib/utopia/redirection.rb', line 102
def max_age
@max_age
end
|
#status ⇒ Object
Returns the value of attribute status
101
102
103
|
# File 'lib/utopia/redirection.rb', line 101
def status
@status
end
|
Instance Method Details
#[](path) ⇒ Object
117
118
119
|
# File 'lib/utopia/redirection.rb', line 117
def [] path
false
end
|
#cache_control ⇒ Object
104
105
106
107
|
# File 'lib/utopia/redirection.rb', line 104
def cache_control
"max-age=#{self.max_age}"
end
|
#call(env) ⇒ Object
121
122
123
124
125
126
127
128
129
|
# File 'lib/utopia/redirection.rb', line 121
def call(env)
path = env[Rack::PATH_INFO]
if redirection = self[path]
return redirection
end
return @app.call(env)
end
|
#freeze ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/utopia/redirection.rb', line 92
def freeze
return self if frozen?
@status.freeze
@max_age.freeze
super
end
|
109
110
111
|
# File 'lib/utopia/redirection.rb', line 109
def (location)
{HTTP::LOCATION => location, HTTP::CACHE_CONTROL => self.cache_control}
end
|
#redirect(location) ⇒ Object
113
114
115
|
# File 'lib/utopia/redirection.rb', line 113
def redirect(location)
return [self.status, self.(location), []]
end
|