Sha256: 6b9229c8a19e94d451b825061b4f9f5b7b3f1c7bf8904648769d6ec36ea6cde9
Contents?: true
Size: 814 Bytes
Versions: 2
Compression:
Stored size: 814 Bytes
Contents
# encoding: UTF-8 # frozen_string_literal: true 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dump-1.2.2 | lib/dump/env/filter.rb |
dump-1.2.1 | lib/dump/env/filter.rb |