Class: Rack::Attack::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/attack/check.rb

Direct Known Subclasses

Blocklist, Safelist

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}, &block) ⇒ Check

Returns a new instance of Check.


8
9
10
11
12
# File 'lib/rack/attack/check.rb', line 8

def initialize(name, options = {}, &block)
  @name = name
  @block = block
  @type = options.fetch(:type, nil)
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.


6
7
8
# File 'lib/rack/attack/check.rb', line 6

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.


6
7
8
# File 'lib/rack/attack/check.rb', line 6

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.


6
7
8
# File 'lib/rack/attack/check.rb', line 6

def type
  @type
end

Instance Method Details

#matched_by?(request) ⇒ Boolean

Returns:

  • (Boolean)

14
15
16
17
18
19
20
21
22
# File 'lib/rack/attack/check.rb', line 14

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