lib/sniffer/config.rb in sniffer-0.3.2 vs lib/sniffer/config.rb in sniffer-0.4.0
- old
+ new
@@ -1,8 +1,10 @@
# frozen_string_literal: true
require "anyway_config"
+require_relative "middleware/chain"
+require_relative "middleware/logger"
module Sniffer
# Sniffer configuration
class Config < Anyway::Config
config_name :sniffer
@@ -22,19 +24,31 @@
store: true,
enabled: false,
url_whitelist: nil,
url_blacklist: nil
+ def middleware
+ @middleware ||= begin
+ Middleware::Chain.new.tap do |chain|
+ chain.add(Sniffer::Middleware::Logger, logger, severity)
+ end
+ end
+
+ yield @middleware if block_given?
+ @middleware
+ end
+
def capacity?
store.is_a?(Hash) && store.key?(:capacity)
end
def capacity
store.fetch(:capacity).to_i
end
def rotate?
return false unless capacity?
+
store.fetch(:rotate, true)
end
end
end