Permalink
Browse files

Added more inline code examples.

  • Loading branch information...
1 parent 655a3e4 commit 80cc3611b84cb44bbcea091f7966044c83af0d4a @bendiken bendiken committed Mar 21, 2010
Showing with 20 additions and 3 deletions.
  1. +5 −3 README.md
  2. +7 −0 lib/rack/throttle/interval.rb
  3. +8 −0 lib/rack/throttle/limiter.rb
View
@@ -11,7 +11,7 @@ with Sinatra.
Examples
--------
-### Adding throttling to a Rack application
+### Adding throttling to a Rackup application
require 'rack/throttle'
@@ -23,13 +23,15 @@ Examples
use Rack::Throttle::Interval, :min => 3.0
-### Using a Memcached server to store rate-limiting counters
+### Using Memcached to store rate-limiting counters
- use Rack::Throttle::Interval, :cache => Memcached.new, :key_prefix => 'throttle'
+ use Rack::Throttle::Interval, :cache => Memcached.new, :key_prefix => :throttle
Documentation
-------------
+<http://datagraph.rubyforge.org/rack-throttle/>
+
* {Rack::Throttle}
* {Rack::Throttle::Interval}
* {Rack::Throttle::Daily}
@@ -3,6 +3,13 @@ module Rack; module Throttle
# This rate limiter strategy throttles the application by enforcing a
# minimum interval (by default, 1 second) between subsequent allowed HTTP
# requests.
+ #
+ # @example Allowing up to two requests per second
+ # use Rack::Throttle::Interval, :min => 0.5 # 500 ms interval
+ #
+ # @example Allowing a request every two seconds
+ # use Rack::Throttle::Interval, :min => 2.0 # 2000 ms interval
+ #
class Interval < Limiter
##
# @param [#call] app
@@ -1,6 +1,14 @@
module Rack; module Throttle
##
# This is the base class for rate limiter implementations.
+ #
+ # @example Defining a rate limiter subclass
+ # class MyLimiter < Limiter
+ # def allowed?(request)
+ # # TODO: custom logic goes here
+ # end
+ # end
+ #
class Limiter
attr_reader :app
attr_reader :options

0 comments on commit 80cc361

Please sign in to comment.