class Rack::Congestion::PathLimiter

Attributes

path[RW]
path_matcher[RW]

Public Class Methods

new(app, options = { }) click to toggle source
Calls superclass method Rack::Congestion::Limiter::new
# File lib/rack/congestion/path_limiter.rb, line 6
def initialize(app, options = { })
  self.path = normalize_path_from options
  self.path_matcher = normalize_matcher_from options
  super
end

Public Instance Methods

_call(env) click to toggle source
Calls superclass method Rack::Congestion::Limiter#_call
# File lib/rack/congestion/path_limiter.rb, line 12
def _call(env)
  @env = env
  ignored? ? app.call(env) : super(env)
end
ignored?() click to toggle source
# File lib/rack/congestion/path_limiter.rb, line 21
def ignored?
  request.path !~ path_matcher
end
key() click to toggle source
# File lib/rack/congestion/path_limiter.rb, line 17
def key
  ->{ path }
end

Protected Instance Methods

normalize_matcher_from(options) click to toggle source
# File lib/rack/congestion/path_limiter.rb, line 32
def normalize_matcher_from(options)
  self.path_matcher = options.delete :path_matcher
  return path_matcher if path_matcher
  Regexp.new path.sub(/^\^?/, '^'), 'i'
end
normalize_path_from(options) click to toggle source
# File lib/rack/congestion/path_limiter.rb, line 27
def normalize_path_from(options)
  self.path = options.delete :path
  path.sub(/^\/*/, '/').sub /\/+$/, ''
end