class Artifactory::Cleaner::ArtifactBucket

A collection of Artifacts within a date range

An Artifactory::Cleaner::ArtifactBucket represents an “age bucket” when analyzing Artifact usage; Artifacts are grouped into buckets of time to aid in developing an archive strategy.

Artifactory::Cleaner::ArtifactBucket is largely just an Array of Artifactory::Resource::Artifact instances, with logic to maintain a filesize count and properties fr the age of the artifacts within.

This class works with the Artifactory::Cleaner::ArtifactBucketCollection class, which maintains a collection of Artifactory::Cleaner::ArtifactBucket instances and handles selecting the proper one for a given Artifact

Attributes

filesize[R]
max[R]
min[R]

Public Class Methods

new(min,max=nil) click to toggle source

ArtifactBucket constructor

Params:

min

Lower bound (in days) for the age of artifacts this bucket should contain

max

Upper bound (in days) for the age of artifacts this bucket should contain, defaults to none (infinity)

# File lib/artifactory/cleaner/artifact_bucket.rb, line 32
def initialize(min,max=nil)
  @min = min
  @max = max.nil? ? Float::INFINITY : max
  @filesize = 0
  @collection = []
end

Public Instance Methods

<<(artifact)
Alias for: push
[]=(key, artifact) click to toggle source

Update an artifact in the bucket

TODO: This method does not validate if the artifact still belongs in this bucket by age

# File lib/artifactory/cleaner/artifact_bucket.rb, line 51
def []=(key, artifact)
  raise TypeError, "expected Artifactory::Resource::Artifact, got #{artifact.class.name}" unless artifact.is_a? Artifactory::Resource::Artifact
  @filesize -= @collection[key].size if @collection[key].is_a? Artifactory::Resource::Artifact
  @filesize += artifact.size
  @collection[key] = artifact
end
covers?(age) click to toggle source

Given an age (in days) return true if this bucket covers that age (if it's within the min and max of this bucket)

# File lib/artifactory/cleaner/artifact_bucket.rb, line 43
def covers?(age)
  age >= @min && age < @max
end
push(artifact) click to toggle source

Add an artifact to the end of this bucket

Calls push on the Array which backs this bucket

Aliased as method `<<`

TODO: This method does not validate if the artifact belongs in this bucket by age

@see: Array#push

# File lib/artifactory/cleaner/artifact_bucket.rb, line 68
def push(artifact)
  raise TypeError, "expected Artifactory::Resource::Artifact, got #{artifact.class.name}" unless artifact.is_a? Artifactory::Resource::Artifact
  @collection.push artifact
  @filesize += artifact.size
  self
end
Also aliased as: <<
recalculate_filesize() click to toggle source

Recalculate the file size of this bucket by adding up the size of all artifacts it contains

This method forces recalculation of the total fize size of all artifacts within this bucket; the filesize is tracked automatically as artifacts are added, so thi method should be unnecessary. It is av available in case the tracking built in to `push`/`unshift`/`[]=` hsa a bug, or in case artifact sizes somehow change

# File lib/artifactory/cleaner/artifact_bucket.rb, line 97
def recalculate_filesize
  @filesize = @collection.reduce(0) {|sum,asset| sum + asset.size}
end
unshift(artifact) click to toggle source

Add an artifact to the beginning of this bucket

Calls unshift on the Array which backs this bucket

TODO: This method does not validate if the artifact belongs in this bucket by age

@see Array#unshift

# File lib/artifactory/cleaner/artifact_bucket.rb, line 84
def unshift(artifact)
  raise TypeError, "expected Artifactory::Resource::Artifact, got #{artifact.class.name}" unless artifact.is_a? Artifactory::Resource::Artifact
  @collection.unshift artifact
  @filesize += artifact.size
  self
end