Object
# File lib/rack/attack.rb, line 26 def blacklist(name, &block) self.blacklists[name] = Blacklist.new(name, block) end
# File lib/rack/attack.rb, line 49 def blacklisted?(req) blacklists.any? do |name, blacklist| blacklist[req] end end
# File lib/rack/attack.rb, line 39 def blacklists; @blacklists ||= {}; end
# File lib/rack/attack.rb, line 71 def cache @cache ||= Cache.new end
# File lib/rack/attack.rb, line 75 def clear! @whitelists, @blacklists, @throttles, @tracks = {}, {}, {}, {} end
# File lib/rack/attack.rb, line 67 def instrument(req) notifier.instrument('rack.attack', req) if notifier end
# File lib/rack/attack.rb, line 89 def initialize(app) @app = app end
# File lib/rack/attack.rb, line 30 def throttle(name, options, &block) self.throttles[name] = Throttle.new(name, options, block) end
# File lib/rack/attack.rb, line 55 def throttled?(req) throttles.any? do |name, throttle| throttle[req] end end
# File lib/rack/attack.rb, line 40 def throttles; @throttles ||= {}; end
# File lib/rack/attack.rb, line 34 def track(name, options = {}, &block) self.tracks[name] = Track.new(name, options, block) end
# File lib/rack/attack.rb, line 61 def tracked?(req) tracks.each_value do |tracker| tracker[req] end end
# File lib/rack/attack.rb, line 22 def whitelist(name, &block) self.whitelists[name] = Whitelist.new(name, block) end
# File lib/rack/attack.rb, line 93 def call(env) req = Rack::Attack::Request.new(env) if whitelisted?(req) @app.call(env) elsif blacklisted?(req) self.class.blacklisted_response[env] elsif throttled?(req) self.class.throttled_response[env] else tracked?(req) @app.call(env) end end
Generated with the Darkfish Rdoc Generator 2.