Class: Artifactory::Cleaner::ArtifactFilterRule

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/artifactory/cleaner/artifact_filter_rule.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action: :include, priority: 0, property: :uri, regex: //) ⇒ ArtifactFilterRule

Returns a new instance of ArtifactFilterRule.



11
12
13
14
15
16
# 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

Instance Attribute Details

#actionObject

Returns the value of attribute action.



32
33
34
# File 'lib/artifactory/cleaner/artifact_filter_rule.rb', line 32

def action
  @action
end

#priorityObject (readonly)

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.



30
31
32
# File 'lib/artifactory/cleaner/artifact_filter_rule.rb', line 30

def priority
  @priority
end

#propertyObject

Returns the value of attribute property.



31
32
33
# File 'lib/artifactory/cleaner/artifact_filter_rule.rb', line 31

def property
  @property
end

#regexObject Also known as: regexp

Returns the value of attribute regex.



18
19
20
# File 'lib/artifactory/cleaner/artifact_filter_rule.rb', line 18

def regex
  @regex
end

Instance Method Details

#<=>(other_rule) ⇒ Object

Compare priority with another rule



72
73
74
75
76
77
78
# 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) ⇒ Object

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



38
39
40
41
42
43
44
# File 'lib/artifactory/cleaner/artifact_filter_rule.rb', line 38

def action_for(artifact)
  if matches?(artifact)
    @action
  else
    false
  end
end

#excludes?(artifact) ⇒ Boolean

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

Returns:

  • (Boolean)


58
59
60
# File 'lib/artifactory/cleaner/artifact_filter_rule.rb', line 58

def excludes?(artifact)
  @type == :exclude && matches?(artifact)
end

#includes?(artifact) ⇒ Boolean

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

Returns:

  • (Boolean)


50
51
52
# File 'lib/artifactory/cleaner/artifact_filter_rule.rb', line 50

def includes?(artifact)
  @type == :include && matches?(artifact)
end

#matches?(artifact) ⇒ Boolean

Does this rule match a given package?

Returns true if the ‘property` of a given artifact matches the `regex`

Returns:

  • (Boolean)


66
67
68
# 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