Class: Rack::Backstage

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/contrib/backstage.rb

Constant Summary collapse

File =
::File

Instance Method Summary collapse

Constructor Details

#initialize(app, path) ⇒ Backstage

Returns a new instance of Backstage.



5
6
7
8
# File 'lib/rack/contrib/backstage.rb', line 5

def initialize(app, path)
  @app = app
  @file = File.expand_path(path)
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/rack/contrib/backstage.rb', line 10

def call(env)
  if File.exists?(@file)
    content = File.read(@file)
    length = "".respond_to?(:bytesize) ? content.bytesize.to_s : content.size.to_s
    [503, {'Content-Type' => 'text/html', 'Content-Length' => length}, [content]]
  else
    @app.call(env)
  end
end