From 5cd776aa1bb88737c8757bcc14e1c213c43207a4 Mon Sep 17 00:00:00 2001 From: fatkodima Date: Thu, 17 Oct 2019 14:30:45 +0300 Subject: [PATCH] Add ability to use multiple instances of middleware --- lib/rack/attack.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/rack/attack.rb b/lib/rack/attack.rb index f533ca6d..64771fc9 100644 --- a/lib/rack/attack.rb +++ b/lib/rack/attack.rb @@ -84,9 +84,15 @@ def clear! attr_reader :configuration - def initialize(app) + def initialize(app, &block) @app = app - @configuration = self.class.configuration + @configuration = + if block_given? + configuration = Configuration.new + configuration.instance_exec(&block) + else + self.class.configuration + end end def call(env)