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.



7
8
9
10
# File 'lib/rack/contrib/backstage.rb', line 7

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

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  if File.exist?(@file)
    content = File.read(@file)
    length = content.bytesize.to_s
    [503, {'content-type' => 'text/html', 'content-length' => length}, [content]]
  else
    @app.call(env)
  end
end