From 0188a90ab26c01a859f093318bab9aecc348d68c Mon Sep 17 00:00:00 2001 From: Gonzalo Rodriguez Date: Thu, 17 Oct 2019 14:27:32 -0300 Subject: [PATCH] refactor: DRY setting config defaults --- lib/rack/attack/configuration.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/rack/attack/configuration.rb b/lib/rack/attack/configuration.rb index b7287e7..160886e 100644 --- a/lib/rack/attack/configuration.rb +++ b/lib/rack/attack/configuration.rb @@ -21,16 +21,7 @@ module Rack attr_accessor :blocklisted_response, :throttled_response, :throttled_response_retry_after_header def initialize - @safelists = {} - @blocklists = {} - @throttles = {} - @tracks = {} - @anonymous_blocklists = [] - @anonymous_safelists = [] - @throttled_response_retry_after_header = false - - @blocklisted_response = DEFAULT_BLOCKLISTED_RESPONSE - @throttled_response = DEFAULT_THROTTLED_RESPONSE + set_defaults end def safelist(name = nil, &block) @@ -92,6 +83,12 @@ module Rack end def clear_configuration + set_defaults + end + + private + + def set_defaults @safelists = {} @blocklists = {} @throttles = {}