Sha256: 3ffaa20592e7ad7be89543d6b2c0910db7e0abcc19b3b82964d5fd8175b395c0

Contents?: true

Size: 877 Bytes

Versions: 1

Compression:

Stored size: 877 Bytes

Contents

# frozen_string_literal: true

module Intercept
  module Strategy
    class WhiteList
      attr_reader :white_list, :fallback_strategy

      def initialize(white_list, fallback_strategy = nil)
        @white_list = white_list
        @fallback_strategy = fallback_strategy
      end

      def process_identities(identities)
        return [] if identities.blank?

        white_listed_identities = white_list_identities(identities)

        if fallback_strategy && white_listed_identities.empty?
          fallback_strategy.process_identities(identities)
        else
          white_listed_identities
        end
      end

      private

      def white_list_identities(identities)
        identities.select do |identity|
          white_list.find do |regex|
            Regexp.new(regex).match?(identity)
          end
        end.compact.uniq
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
intercept-0.2.0 lib/intercept/strategy/white_list.rb