Class: Rack::Apocalypse404
- Inherits:
-
Object
- Object
- Rack::Apocalypse404
- Defined in:
- lib/apocalypse-404/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Apocalypse404
constructor
A new instance of Apocalypse404.
Constructor Details
#initialize(app) ⇒ Apocalypse404
Returns a new instance of Apocalypse404.
4 5 6 |
# File 'lib/apocalypse-404/middleware.rb', line 4 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/apocalypse-404/middleware.rb', line 8 def call(env) status, headers, response = @app.call(env) if status.to_i > 400 puts " -- #{status} -- Redirecting to apocalyptic message...." spec = Gem::Specification.find_by_name("apocalypse-404") filename = File.join( spec.gem_dir, 'lib', 'html' ) + "/404.html" response = [File.read( filename ).gsub!(/!!MESSAGE/, status.to_s )] headers = { "Content-Length" => response[0].length.to_s, "Content-Type" => 'text/html;charset=utf-8' } end [ status, headers, response ] end |