Class: Rack::Attack::ConditionalThrottle

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

Constant Summary

Constants inherited from Throttle

Throttle::MANDATORY_OPTIONS

Instance Attribute Summary

Attributes inherited from Throttle

#block, #limit, #name, #period, #type

Instance Method Summary collapse

Methods inherited from Throttle

#[], #cache, #initialize

Constructor Details

This class inherits a constructor from Rack::Attack::Throttle

Instance Method Details

#get_count(discriminator) ⇒ Object



10
11
12
13
14
# File 'lib/rack/attack/conditional_throttle.rb', line 10

def get_count(discriminator)
  key = "#{name}:#{discriminator}"
  count = cache.get_count(key, period)
  count ? count.to_i : 0
end

#increment_counter(discriminator) ⇒ Object



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

def increment_counter(discriminator)
  key = "#{name}:#{discriminator}"
  cache.count(key, period)
end