mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
refactor: make Throttle.new consistent with Blocklist/Safelist.new
This commit is contained in:
parent
3639afc196
commit
0e8dff4c88
3 changed files with 3 additions and 3 deletions
|
|
@ -58,7 +58,7 @@ class Rack::Attack
|
||||||
end
|
end
|
||||||
|
|
||||||
def throttle(name, options, &block)
|
def throttle(name, options, &block)
|
||||||
throttles[name] = Throttle.new(name, options, block)
|
throttles[name] = Throttle.new(name, options, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def track(name, options = {}, &block)
|
def track(name, options = {}, &block)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ module Rack
|
||||||
MANDATORY_OPTIONS = [:limit, :period].freeze
|
MANDATORY_OPTIONS = [:limit, :period].freeze
|
||||||
|
|
||||||
attr_reader :name, :limit, :period, :block, :type
|
attr_reader :name, :limit, :period, :block, :type
|
||||||
def initialize(name, options, block)
|
def initialize(name, options, &block)
|
||||||
@name, @block = name, block
|
@name, @block = name, block
|
||||||
MANDATORY_OPTIONS.each do |opt|
|
MANDATORY_OPTIONS.each do |opt|
|
||||||
raise ArgumentError, "Must pass #{opt.inspect} option" unless options[opt]
|
raise ArgumentError, "Must pass #{opt.inspect} option" unless options[opt]
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ module Rack
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue