Class: SlowWeb
- Inherits:
-
Object
- Object
- SlowWeb
- Defined in:
- lib/slow_web.rb,
lib/slow_web/limit.rb,
lib/slow_web/version.rb
Defined Under Namespace
Classes: Limit
Constant Summary collapse
- VERSION =
'0.1.1'
Class Method Summary collapse
-
.get_limit(host) ⇒ SlowWeb::Limit
Retrieves the limit object for a given host.
-
.limit(host, count, period) ⇒ SlowWeb::Limit
Limits the number of requests that can occur within a specified number of seconds.
-
.limit_exceeded?(host) ⇒ Boolean
A flag stating if the limit for a given host has been exceeded.
-
.reset ⇒ Object
Removes all limits.
Class Method Details
.get_limit(host) ⇒ SlowWeb::Limit
Retrieves the limit object for a given host.
39 40 41 |
# File 'lib/slow_web.rb', line 39 def self.get_limit(host) return @limits[host] end |
.limit(host, count, period) ⇒ SlowWeb::Limit
Limits the number of requests that can occur within a specified number of seconds.
26 27 28 29 30 31 32 |
# File 'lib/slow_web.rb', line 26 def self.limit(host, count, period) raise "Limit already exists for this host: #{host}" if @limits[host] limit = Limit.new(host, count, period) @limits[host] = limit return limit end |
.limit_exceeded?(host) ⇒ Boolean
A flag stating if the limit for a given host has been exceeded.
48 49 50 51 |
# File 'lib/slow_web.rb', line 48 def self.limit_exceeded?(host) limit = @limits[host] return !limit.nil? && limit.exceeded? end |
.reset ⇒ Object
Removes all limits.
55 56 57 |
# File 'lib/slow_web.rb', line 55 def self.reset @limits = {} end |