rack-attack/lib/rack/attack/check.rb
Lucas Mansur 11e9557ccb [Fixes #302] Initial style guide adoption (#330)
* Initial Rubocop configuration

* Fix Rubocop layout offenses for lib

* Fix some spec offenses

* Fix leftover layout offenses
2018-03-30 16:08:00 -03:00

23 lines
518 B
Ruby

module Rack
class Attack
class Check
attr_reader :name, :block, :type
def initialize(name, options = {}, block)
@name, @block = name, block
@type = options.fetch(:type, nil)
end
def [](req)
block[req].tap { |match|
if match
req.env["rack.attack.matched"] = name
req.env["rack.attack.match_type"] = type
Rack::Attack.instrument(req)
end
}
end
alias_method :match?, :[]
end
end
end