mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
* attempt to improve semantics for legibility * Attempt to improve legibility by simplifying * Make it more clear that we're calling procs/blocks here * Enable rubocop Style/BlockDelimiters cop * Prefer 'request' over 'req' abbreviation for legibility/clarity * Instances of Track named 'track' not 'tracker'
21 lines
522 B
Ruby
21 lines
522 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 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
|