From a1611761420be6cf4fcb75294aee04121461ed6f Mon Sep 17 00:00:00 2001 From: Genadi Samokovarov Date: Tue, 23 Sep 2014 12:59:37 +0200 Subject: [PATCH] Invoke {blacklisted,throttled}_response with #call I have a response which is a class. While I can still have my class implement `#[]`, it does look a bit off. On the other side, having objects, responding to #call, that are not procs is pretty common. So I propose to invoke the responses with `#call` to let users override it with response objects, that respond to `#call` instead of `#[]`. --- README.md | 4 ++-- lib/rack/attack.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d6d53e1..c4970aa 100644 --- a/README.md +++ b/README.md @@ -73,9 +73,9 @@ def call(env) if whitelisted?(req) @app.call(env) elsif blacklisted?(req) - blacklisted_response[env] + self.class.blacklisted_response.call(env) elsif throttled?(req) - throttled_response[env] + self.class.throttled_response.call(env) else tracked?(req) @app.call(env) diff --git a/lib/rack/attack.rb b/lib/rack/attack.rb index 4dab44d..dd4d1b0 100644 --- a/lib/rack/attack.rb +++ b/lib/rack/attack.rb @@ -96,9 +96,9 @@ class Rack::Attack if whitelisted?(req) @app.call(env) elsif blacklisted?(req) - self.class.blacklisted_response[env] + self.class.blacklisted_response.call(env) elsif throttled?(req) - self.class.throttled_response[env] + self.class.throttled_response.call(env) else tracked?(req) @app.call(env)