Class: Stitches::AllowlistMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/stitches/allowlist_middleware.rb

Overview

A middleware that will skip its behavior if the path matches an allowed URL

Direct Known Subclasses

ApiKey, ValidMimeType

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of AllowlistMiddleware.



4
5
6
7
8
9
10
11
12
13
# File 'lib/stitches/allowlist_middleware.rb', line 4

def initialize(app, options={})

  @app           = app
  @configuration = options[:configuration] ||  Stitches.configuration
  @except        = options[:except]        || @configuration.allowlist_regexp

  unless @except.nil? || @except.is_a?(Regexp)
    raise ":except must be a Regexp"
  end
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/stitches/allowlist_middleware.rb', line 14

def call(env)
  if @except && @except.match(env["PATH_INFO"])
    @app.call(env)
  else
    do_call(env)
  end
end