Class: Utopia::Redirection::Redirection
- Inherits:
-
Object
- Object
- Utopia::Redirection::Redirection
show all
- Defined in:
- lib/utopia/redirection.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(app, status: 307, max_age: DEFAULT_MAX_AGE) ⇒ Redirection
Returns a new instance of Redirection.
81
82
83
84
85
|
# File 'lib/utopia/redirection.rb', line 81
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.
95
96
97
|
# File 'lib/utopia/redirection.rb', line 95
def max_age
@max_age
end
|
#status ⇒ Object
Returns the value of attribute status.
94
95
96
|
# File 'lib/utopia/redirection.rb', line 94
def status
@status
end
|
Instance Method Details
#[](path) ⇒ Object
110
111
112
|
# File 'lib/utopia/redirection.rb', line 110
def [] path
false
end
|
#cache_control ⇒ Object
97
98
99
100
|
# File 'lib/utopia/redirection.rb', line 97
def cache_control
"max-age=#{self.max_age}"
end
|
#call(env) ⇒ Object
114
115
116
117
118
119
120
121
122
|
# File 'lib/utopia/redirection.rb', line 114
def call(env)
path = env[Rack::PATH_INFO]
if redirection = self[path]
return redirection
end
return @app.call(env)
end
|
#freeze ⇒ Object
87
88
89
90
91
92
|
# File 'lib/utopia/redirection.rb', line 87
def freeze
@status.freeze
@max_age.freeze
super
end
|
102
103
104
|
# File 'lib/utopia/redirection.rb', line 102
def (location)
{HTTP::LOCATION => location, HTTP::CACHE_CONTROL => self.cache_control}
end
|
#redirect(location) ⇒ Object
106
107
108
|
# File 'lib/utopia/redirection.rb', line 106
def redirect(location)
return [self.status, self.(location), []]
end
|