Added track with limit/period options example to the README.md for clarity.

This commit is contained in:
Paul Coates 2014-05-19 12:30:18 -07:00
parent c51676d295
commit 1857f8dd57

View file

@ -188,11 +188,16 @@ end
### Tracks
```ruby
# Track requests from a special user agent, supports limit and period options like throttle.
# Track requests from a special user agent.
Rack::Attack.track("special_agent") do |req|
req.user_agent == "SpecialAgent"
end
# Supports optional limit and period, triggers the notification only when the limit is reached.
Rack::Attack.track("special_agent", :limit 6, :period => 60.seconds) do |req|
req.user_agent == "SpecialAgent"
end
# Track it using ActiveSupport::Notification
ActiveSupport::Notifications.subscribe("rack.attack") do |name, start, finish, request_id, req|
if req.env['rack.attack.matched'] == "special_agent" && req.env['rack.attack.match_type'] == :track