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

action[RW]
priority[R]

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.

property[RW]
regex[R]
regexp[R]

Public Class Methods

new(action: :include, priority: 0, property: :uri, regex: //) click to toggle source
# 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

<=>(other_rule) click to toggle source

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
action_for(artifact) click to toggle source

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
excludes?(artifact) click to toggle source

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
includes?(artifact) click to toggle source

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
matches?(artifact) click to toggle source

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
regex=(re) click to toggle source

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
Also aliased as: regexp=
regexp=(re)
Alias for: regex=