Class: Rack::MaintenanceMode::Middleware
- Inherits:
-
Object
- Object
- Rack::MaintenanceMode::Middleware
- Defined in:
- lib/rack/maintenance_mode/middleware.rb
Overview
A Rack middleware to automatically put the Rack application into maintenance mode (HTTP 503).
The default behaviour may be overridden by passing specific options at the time of initialization.
Available options:
‘:if` - Any object which responds to `call(hash)` and returns a true/false-like result. Used for determining whether or not we’re in maintenance mode.
‘:response` - Any object which responds to `call(hash)` and returns a Rack-compatible response array. Used for generating the client response when in maintenance mode.
Constant Summary collapse
- DEFAULT_RESPONSE =
Proc.new { |env| [503, {"Content-Type" => "text/html"}, ["<html><body><h2>We are undergoing maintenance right now, please try again soon.</body></html>"]] }
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
25 26 27 28 29 |
# File 'lib/rack/maintenance_mode/middleware.rb', line 25 def initialize(app, = {}) @app = app @mode_check = [:if] || DefaultModeCheck @response = [:response] || DEFAULT_RESPONSE end |
Instance Method Details
#call(env) ⇒ Object
31 32 33 |
# File 'lib/rack/maintenance_mode/middleware.rb', line 31 def call(env) maintenance_mode?(env) ? maintenance_response(env) : standard_response(env) end |