Sha256: e7f224644e1962ffe5c831a52288bed54c072f0277dc1653167c58203b851b6c

Contents?: true

Size: 757 Bytes

Versions: 1

Compression:

Stored size: 757 Bytes

Contents

# encoding: UTF-8

class DumpRake
  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(s, splitter = nil)
        if s
          s = s.dup
          @invert = !!s.sub!(/^-/, '')
          @values = s.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.0.5 lib/dump_rake/env/filter.rb