Class: Moku::ArtifactRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/moku/artifact_repo.rb

Overview

Repository for built artifacts

Instance Method Summary collapse

Constructor Details

#initialize(dir, max_cache: Moku.build_cache_max) ⇒ ArtifactRepo

Returns a new instance of ArtifactRepo.

Parameters:

  • dir (Pathname)

    A directory in which to store artifacts


14
15
16
17
18
# File 'lib/moku/artifact_repo.rb', line 14

def initialize(dir, max_cache: Moku.build_cache_max)
  @dir = Pathname.new(dir).tap(&:mkpath)
  @max_cache = (max_cache - 1) || 1
  # -1 because we prune before building, so we won't reach it until max + 1.
end

Instance Method Details

#for(signature, plan) ⇒ Array<Artifact,Status>

Obtain the build for the given instance and signature, and build it using the given plan if it is not already built. This operation is idempotent.

Any errors raised in the build process are re-raised. Artifacts that fail to build successfully are purged.

Parameters:

  • signature (ReleaseSignature)
  • plan (Class)

    The class, which should be Plan::Plan

Returns:

  • (Array<Artifact,Status>)

    The built artifact, and whether or not it was successful.


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/moku/artifact_repo.rb', line 31

def for(signature, plan)
  cleanup!

  artifact = artifact_for(signature)
  status = if artifact.path.exist?
    Status.success
  else
    plan.new(artifact).call
  end

  [artifact, status]
ensure
  FileUtils.remove_entry_secure(artifact.path) unless status&.success?
end