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.



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

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

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



4
5
6
# File 'lib/rack/attack/check.rb', line 4

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/rack/attack/check.rb', line 4

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/rack/attack/check.rb', line 4

def type
  @type
end

Instance Method Details

#[](req) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/rack/attack/check.rb', line 10

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