Sha256: 5045b8b284741e96bd5eef93f0986af9138bdb538b882ce1ea6e1823f455df32
Contents?: true
Size: 950 Bytes
Versions: 2
Compression:
Stored size: 950 Bytes
Contents
module ConfCtl::Cli class AttrFilters # @param str_filters [Array<String>] def initialize(str_filters) @filters = parse_all(str_filters) end # @param machine [ConfCtl::Machine] def pass?(machine) filters.all? { |f| f.call(machine) } end protected attr_reader :filters def parse_all(str_filters) ret = [] str_filters.each do |s| k, v = parse_one(s, '!=') if k ret << proc do |machine| machine[k].to_s != v end next end k, v = parse_one(s, '=') if k ret << proc do |machine| machine[k].to_s == v end next end raise GLI::BadCommandLine, "Invalid filter '#{v}'" end ret end def parse_one(v, sep) i = v.index(sep) return false unless i len = sep.length [v[0..i - 1], v[i + len..]] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
confctl-2.0.0 | lib/confctl/cli/attr_filters.rb |
confctl-1.0.0 | lib/confctl/cli/attr_filters.rb |