rack-attack/lib/rack/attack/check.rb
Olle Jonsson 44b6a7353a
Use RuboCop 0.84.0
- this enables each of the new Cops and marks each with the version
they appeared in

(cherry picked from commit c07fcdde43)
2021-01-23 13:55:46 -03:00

25 lines
563 B
Ruby

# frozen_string_literal: true
module Rack
class Attack
class Check
attr_reader :name, :block, :type
def initialize(name, options = {}, &block)
@name = name
@block = block
@type = options.fetch(:type, nil)
end
def matched_by?(request)
block.call(request).tap do |match|
if match
request.env["rack.attack.matched"] = name
request.env["rack.attack.match_type"] = type
Rack::Attack.instrument(request)
end
end
end
end
end
end