Class: ShuntCache::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/shunt_cache/middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Middleware.



5
6
7
8
9
10
# 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

Instance Attribute Details

#endpoint_matcherObject

Returns the value of attribute endpoint_matcher.



3
4
5
# File 'lib/shunt_cache/middleware.rb', line 3

def endpoint_matcher
  @endpoint_matcher
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# 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