class Artifactory::Cleaner::ArtifactFilterRule
Filter a collection of artifacts based on include/deny rules
The Artifactory::Cleaner::ArtifactFilterRile class represents a whitelist or blacklist entry. It matches a package and then targets that package for inclusion or exclusion.
Attributes
TODO: Allow changing priority. Right now this would cause problems because if the rule is in a filer, the filter won't be sorted properly after this change.
Public Class Methods
# File lib/artifactory/cleaner/artifact_filter_rule.rb, line 11 def initialize(action: :include, priority: 0, property: :uri, regex: //) @regex = regex if regex.is_a? Regexp @action = action @priority = priority.to_i @property = property.to_sym end
Public Instance Methods
Compare priority with another rule
# File lib/artifactory/cleaner/artifact_filter_rule.rb, line 72 def <=>(other_rule) if other_rule.is_a? ArtifactFilterRule @priority <=> other_rule.priority else nil end end
Does this rule trigger an action on a given artifact?
This method returns true if the given artifact matches the criteria of this rule, and the rule is of type :include
# File lib/artifactory/cleaner/artifact_filter_rule.rb, line 38 def action_for(artifact) if matches?(artifact) @action else false end end
Does this rule determine that an artifact should be excluded?
This method returns true if the given artifact matches the criteria of this rule, and the rule is of type :exclude
# File lib/artifactory/cleaner/artifact_filter_rule.rb, line 58 def excludes?(artifact) @type == :exclude && matches?(artifact) end
Does this rule determine that an artifact should be included?
This method returns true if the given artifact matches the criteria of this rule, and the rule is of type :include
# File lib/artifactory/cleaner/artifact_filter_rule.rb, line 50 def includes?(artifact) @type == :include && matches?(artifact) end
Does this rule match a given package?
Returns true if the `property` of a given artifact matches the `regex`
# File lib/artifactory/cleaner/artifact_filter_rule.rb, line 66 def matches?(artifact) @regex.is_a? Regexp and @regex.match?(artifact.send(@property).to_s) end
Change the regex of this rule
# File lib/artifactory/cleaner/artifact_filter_rule.rb, line 22 def regex=(re) raise TypeError, 'Expected a Regexp' unless re.is_a? Regexp @regex = re end