Sha256: a744b593ef733d88b1caee824b265a5d592055b36d8dcf673357ad82d8612462

Contents?: true

Size: 590 Bytes

Versions: 4

Compression:

Stored size: 590 Bytes

Contents

module Rack; module Throttle
  ##
  class TimeWindow < Limiter
    ##
    # Returns `true` if fewer than the maximum number of requests permitted
    # for the current window of time have been made.
    #
    # @param  [Rack::Request] request
    # @return [Boolean]
    def allowed?(request)
      return true if whitelisted?(request)
      count = cache_get(key = cache_key(request)).to_i + 1 rescue 1
      allowed = count <= max_per_window(request).to_i
      begin
        cache_set(key, count)
        allowed
      rescue => e
        allowed = true
      end
    end
  end
end; end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rack-throttle-0.7.1 lib/rack/throttle/time_window.rb
rack-throttle-0.7.0 lib/rack/throttle/time_window.rb
rack-throttle-0.6.0 lib/rack/throttle/time_window.rb
rack-throttle-0.5.0 lib/rack/throttle/time_window.rb