class ShuntCache::Middleware

Attributes

endpoint_matcher[RW]

Public Class Methods

new(app, options = {}) click to toggle source
# File lib/shunt_cache/middleware.rb, line 5
def initialize(app, options = {})
  @app = app
  @endpoint_matcher = options.fetch(:endpoint) do
    "/options/full_stack_status"
  end
end

Public Instance Methods

call(env) click to toggle source
# File lib/shunt_cache/middleware.rb, line 12
def call(env)
  path = env.fetch('REQUEST_PATH') do
    env.fetch('PATH_INFO') do
      env.fetch('REQUEST_URI', '')
    end
  end
  if path.match(endpoint_matcher) && ShuntCache::Status.shunted?
    return ['503', {'Content-Type' => 'text/html'}, ['Maintenance']]
  end
  @app.call(env)
end