Sha256: b04d663707fa7c39241d605f8360dc9e069807bd25ae65a1e64b7c784fa6e22b

Contents?: true

Size: 640 Bytes

Versions: 5

Compression:

Stored size: 640 Bytes

Contents

# frozen_string_literal: true

module Sniffer
  # match request with white and black lists
  module RequestPolicy
    class << self
      def call(request)
        url = "#{request.host}:#{request.port}"
        if config.url_whitelist
          whitelist_url?(url)
        elsif config.url_blacklist
          !blacklist_url?(url)
        else
          true
        end
      end

      private

      def whitelist_url?(url)
        !url.match(config.url_whitelist).nil?
      end

      def blacklist_url?(url)
        !url.match(config.url_blacklist).nil?
      end

      def config
        Sniffer.config
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sniffer-0.5.0 lib/sniffer/request_policy.rb
sniffer-0.4.0 lib/sniffer/request_policy.rb
sniffer-0.3.2 lib/sniffer/request_policy.rb
sniffer-0.3.1 lib/sniffer/request_policy.rb
sniffer-0.3.0 lib/sniffer/request_policy.rb