Class: ThrottleMachines::RackMiddleware::Safelist

Inherits:
Object
  • Object
show all
Defined in:
lib/throttle_machines/rack_middleware/safelist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Safelist

Returns a new instance of Safelist.



8
9
10
11
# File 'lib/throttle_machines/rack_middleware/safelist.rb', line 8

def initialize(name, &block)
  @name = name
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



6
7
8
# File 'lib/throttle_machines/rack_middleware/safelist.rb', line 6

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/throttle_machines/rack_middleware/safelist.rb', line 6

def name
  @name
end

Instance Method Details

#matched_by?(request) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/throttle_machines/rack_middleware/safelist.rb', line 13

def matched_by?(request)
  return false unless @block

  if @block.call(request)
    request.env['rack.attack.matched'] = @name
    request.env['rack.attack.match_type'] = :safelist
    ThrottleMachines::RackMiddleware.instrument(request)
    true
  else
    false
  end
end