Sha256: 3facb596195c51b299c227837456f4c1f306998d4410851f1f247710660a9b18

Contents?: true

Size: 587 Bytes

Versions: 2

Compression:

Stored size: 587 Bytes

Contents

module ConfCtl::Cli
  class TagFilters
    # @param str_tags [Array<String>]
    def initialize(str_tags)
      @must = []
      @cant = []
      parse_all(str_tags)
    end

    # @param machine [ConfCtl::Machine]
    def pass?(machine)
      must.all? { |t| machine['tags'].include?(t) } \
        && cant.all? { |t| !machine['tags'].include?(t) }
    end

    protected

    attr_reader :must, :cant

    def parse_all(str_tags)
      str_tags.each do |t|
        if t.start_with?('^')
          cant << t[1..]
        else
          must << t
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
confctl-2.0.0 lib/confctl/cli/tag_filters.rb
confctl-1.0.0 lib/confctl/cli/tag_filters.rb