class Artifactory::Cleaner::DiscoveredArtifact

An Artifact discovered during a repository search

This class is a wrapper of Artifactory::Resource::Artifact because the parent class does not have a concept of `last_downloaded` nor the most recent date for any action on an Artifact. These are important to deciding if an Artifcat should be deleted

Public Class Methods

earliest_date_from(artifact) click to toggle source

Given an Artifactory::Resource::Artifact, return the value of the earliest date property on that object

Designed to answer the question “what's the first time anything happened to a given Artifact?”, this method returns the earliest (longest ago) date from the given artifact's created, last modified and last downloaded timestamps.

# File lib/artifactory/cleaner/discovered_artifact.rb, line 48
def self.earliest_date_from(artifact)
  [
      artifact.created,
      artifact.last_modified,
      artifact.respond_to?(:last_downloaded) ? artifact.last_downloaded : nil,
  ].compact.sort.first
end
latest_date_from(artifact) click to toggle source

Given an Artifactory::Resource::Artifact, return the value of the latest date property on that object

Designed to answer the question “what's the most recent interaction with a given Artifact?”, this method returns the latest (most recent) date from the given artifact's created, last modified and last downloaded timestamps.

# File lib/artifactory/cleaner/discovered_artifact.rb, line 62
def self.latest_date_from(artifact)
  [
      artifact.created,
      artifact.last_modified,
      artifact.respond_to?(:last_downloaded) ? artifact.last_downloaded : nil,
  ].compact.sort.last
end

Public Instance Methods

earliest_date() click to toggle source

What's the earliest Time of any of the date/time properties on this object?

# File lib/artifactory/cleaner/discovered_artifact.rb, line 19
def earliest_date
  self.class.earliest_date_from(self)
end
filename() click to toggle source

The filename componet (basename) of this artifact's URL

# File lib/artifactory/cleaner/discovered_artifact.rb, line 31
def filename
  uri = URI(self.uri)
  File.basename(uri.path)
end
last_downloaded() click to toggle source

Time representing the date and time this artifact was last downloaded by a client (presumably to be installed)

# File lib/artifactory/cleaner/discovered_artifact.rb, line 15
attribute :last_downloaded
latest_date() click to toggle source

What's the most recent Time of any of the date/time properties on this object?

# File lib/artifactory/cleaner/discovered_artifact.rb, line 25
def latest_date
  self.class.latest_date_from(self)
end
to_s() click to toggle source

A string representation of this artifact

# File lib/artifactory/cleaner/discovered_artifact.rb, line 38
def to_s
  "#<DiscoveredArtifact #{filename} last accessed #{latest_date}>"
end