Class: Rack::Maintenance

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

Defined Under Namespace

Classes: InvalidStatus

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Maintenance

Returns a new instance of Maintenance.

Raises:



6
7
8
9
10
11
12
13
14
15
# File 'lib/rack/maintenance.rb', line 6

def initialize(app, options = {})

  raise InvalidStatus if options[:status] && options[:status].to_i < 100

  @app      = app
  @status   = options[:status] || default_status
  @headers  = options[:headers] || default_headers
  @template = options[:template] || default_template
  @active   = options[:active].nil? ? true : options[:active]
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/rack/maintenance.rb', line 17

def call(env)
  if active?
    headers['Content-Length'] = body.bytesize.to_s
    return [status, headers, [body]]
  end
  
  @app.call(env)
end