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 `#[]`.
This commit is contained in:
Genadi Samokovarov 2014-09-23 12:59:37 +02:00
parent 60d4834969
commit a161176142
2 changed files with 4 additions and 4 deletions

View file

@ -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)

View file

@ -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)