style: enable Style/OptionalArguments rubocop

This commit is contained in:
Gonzalo Rodriguez 2019-03-01 21:51:15 -03:00
parent 7daeac3401
commit 5a42fd3ac7
No known key found for this signature in database
GPG key ID: 5DB8B81B049B8AB1
6 changed files with 13 additions and 10 deletions

View file

@ -53,6 +53,9 @@ Style/FrozenStringLiteralComment:
Style/HashSyntax: Style/HashSyntax:
Enabled: true Enabled: true
Style/OptionalArguments:
Enabled: true
Style/RaiseArgs: Style/RaiseArgs:
Enabled: true Enabled: true

View file

@ -30,7 +30,7 @@ class Rack::Attack
attr_accessor :notifier, :blocklisted_response, :throttled_response, :anonymous_blocklists, :anonymous_safelists attr_accessor :notifier, :blocklisted_response, :throttled_response, :anonymous_blocklists, :anonymous_safelists
def safelist(name = nil, &block) def safelist(name = nil, &block)
safelist = Safelist.new(name, block) safelist = Safelist.new(name, &block)
if name if name
safelists[name] = safelist safelists[name] = safelist
@ -40,7 +40,7 @@ class Rack::Attack
end end
def blocklist(name = nil, &block) def blocklist(name = nil, &block)
blocklist = Blocklist.new(name, block) blocklist = Blocklist.new(name, &block)
if name if name
blocklists[name] = blocklist blocklists[name] = blocklist
@ -51,12 +51,12 @@ class Rack::Attack
def blocklist_ip(ip_address) def blocklist_ip(ip_address)
ip_blocklist_proc = lambda { |request| IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) } ip_blocklist_proc = lambda { |request| IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) }
anonymous_blocklists << Blocklist.new(nil, ip_blocklist_proc) anonymous_blocklists << Blocklist.new(nil, &ip_blocklist_proc)
end end
def safelist_ip(ip_address) def safelist_ip(ip_address)
ip_safelist_proc = lambda { |request| IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) } ip_safelist_proc = lambda { |request| IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) }
anonymous_safelists << Safelist.new(nil, ip_safelist_proc) anonymous_safelists << Safelist.new(nil, &ip_safelist_proc)
end end
def throttle(name, options, &block) def throttle(name, options, &block)
@ -64,7 +64,7 @@ class Rack::Attack
end end
def track(name, options = {}, &block) def track(name, options = {}, &block)
tracks[name] = Track.new(name, options, block) tracks[name] = Track.new(name, options, &block)
end end
def safelists; def safelists;

View file

@ -3,7 +3,7 @@
module Rack module Rack
class Attack class Attack
class Blocklist < Check class Blocklist < Check
def initialize(name, block) def initialize(name, &block)
super super
@type = :blocklist @type = :blocklist
end end

View file

@ -4,7 +4,7 @@ module Rack
class Attack class Attack
class Check class Check
attr_reader :name, :block, :type attr_reader :name, :block, :type
def initialize(name, options = {}, block) def initialize(name, options = {}, &block)
@name, @block = name, block @name, @block = name, block
@type = options.fetch(:type, nil) @type = options.fetch(:type, nil)
end end

View file

@ -3,7 +3,7 @@
module Rack module Rack
class Attack class Attack
class Safelist < Check class Safelist < Check
def initialize(name, block) def initialize(name, &block)
super super
@type = :safelist @type = :safelist
end end

View file

@ -5,13 +5,13 @@ module Rack
class Track class Track
attr_reader :filter attr_reader :filter
def initialize(name, options = {}, block) def initialize(name, options = {}, &block)
options[:type] = :track options[:type] = :track
if options[:limit] && options[:period] if options[:limit] && options[:period]
@filter = Throttle.new(name, options, block) @filter = Throttle.new(name, options, block)
else else
@filter = Check.new(name, options, block) @filter = Check.new(name, options, &block)
end end
end end