Class: SlowWeb::Limit
- Inherits:
-
Object
- Object
- SlowWeb::Limit
- Defined in:
- lib/slow_web/limit.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
The number of requests that are allowed within the time period.
-
#host ⇒ Object
The host to restrict.
-
#period ⇒ Object
The number of seconds in the time period.
Instance Method Summary collapse
-
#add_request(request) ⇒ Object
Adds a request that is associated with this limit.
-
#current_request_count ⇒ Object
The number of requests that have occurred within the current period.
-
#exceeded? ⇒ Boolean
A flag stating if the number of requests within the period has been met.
-
#initialize(host, count, period) ⇒ Limit
constructor
A new instance of Limit.
Constructor Details
#initialize(host, count, period) ⇒ Limit
Returns a new instance of Limit.
13 14 15 16 17 18 19 |
# File 'lib/slow_web/limit.rb', line 13 def initialize(host, count, period) @host = host @count = count @period = period @requests = [] end |
Instance Attribute Details
#count ⇒ Object
The number of requests that are allowed within the time period.
30 31 32 |
# File 'lib/slow_web/limit.rb', line 30 def count @count end |
#host ⇒ Object
The host to restrict.
27 28 29 |
# File 'lib/slow_web/limit.rb', line 27 def host @host end |
#period ⇒ Object
The number of seconds in the time period.
33 34 35 |
# File 'lib/slow_web/limit.rb', line 33 def period @period end |
Instance Method Details
#add_request(request) ⇒ Object
Adds a request that is associated with this limit
54 55 56 57 58 |
# File 'lib/slow_web/limit.rb', line 54 def add_request(request) @requests << {:obj => request, :time => Time.now} normalize_requests() nil end |
#current_request_count ⇒ Object
The number of requests that have occurred within the current period.
36 37 38 39 |
# File 'lib/slow_web/limit.rb', line 36 def current_request_count normalize_requests() return @requests.length end |
#exceeded? ⇒ Boolean
A flag stating if the number of requests within the period has been met.
42 43 44 |
# File 'lib/slow_web/limit.rb', line 42 def exceeded? return current_request_count >= count end |