Sha256: 96b1dba0cf1bb31fdd511c8de617cc59ea87076759cc853f16fae4ff4e9a0a2c

Contents?: true

Size: 784 Bytes

Versions: 1

Compression:

Stored size: 784 Bytes

Contents

# encoding: UTF-8

module Dump
  module Env
    # Filter strings by simple pattern:
    #   'a,b,c' will pass only 'a', 'b' and 'c'
    #   '-a,b,c' will pass everything except 'a', 'b' and 'c'
    class Filter
      attr_reader :invert, :values, :transparent
      def initialize(string, splitter = nil)
        if string
          string = string.dup
          @invert = !!string.sub!(/^-/, '')
          @values = string.split(splitter || ',').map(&:strip).map(&:downcase).uniq.select(&:present?)
        else
          @transparent = true
        end
      end

      def pass?(value)
        transparent || (invert ^ values.include?(value.to_s.downcase))
      end

      def custom_pass?(&block)
        transparent || (invert ^ values.any?(&block))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dump-1.2.0 lib/dump/env/filter.rb