Permalink
Browse files

Minor doc comments, no code change.

  • Loading branch information...
1 parent b101a5b commit 6ee33ac7795265b69ca05d85ba96370fbd4e2b69 @bemurphy bemurphy committed Mar 22, 2010
Showing with 13 additions and 2 deletions.
  1. +4 −1 lib/rack/throttle/daily.rb
  2. +3 −0 lib/rack/throttle/hourly.rb
  3. +6 −1 lib/rack/throttle/time_window.rb
@@ -15,7 +15,10 @@ def max_per_day
alias_method :max_per_window, :max_per_day
protected
-
+
+ ##
+ # @param [Rack::Request] request
+ # @return [String]
def cache_key(request)
super + "_" + Time.now.strftime("%Y-%m-%d")
end
@@ -13,6 +13,9 @@ def max_per_hour
protected
+ ##
+ # @param [Rack::Request] request
+ # @return [String]
def cache_key(request)
super + "_" + Time.now.strftime("%Y-%m-%d-%H")
end
@@ -1,5 +1,11 @@
module Rack; module Throttle
class TimeWindow < Limiter
+ ##
+ # Returns `true` if fewer than the max number of requests permitted
+ # for the current window of time have been made.
+ #
+ # @param [Rack::Request] request
+ # @return [Boolean]
def allowed?(request)
count = cache_get(key = cache_key(request)).to_i + 1 rescue 1
allowed = count <= max_per_window
@@ -10,6 +16,5 @@ def allowed?(request)
allowed = true
end
end
-
end
end; end

0 comments on commit 6ee33ac

Please sign in to comment.