Class: Moku::Artifact

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Bundleable
Defined in:
lib/moku/artifact.rb

Overview

A set of files on disk as they will be uploaded to an application server. An artifact is the result of a complete build phase. It contains all of the source files, config files, and generated components. Artifacts are isolated from external services, and generation of artifacts is idempotent.

Internally, artifacts are files on disk under a top level directory. The arrangement of these files is part of the API. Artifacts are deployed to target hosts in the deploy phase.

While this class represents the artifact itself, and should therefore be the source of information about the artifact, the responsibility for building it lies elsewhere.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Bundleable

#with_env

Constructor Details

#initialize(path:, signature:, runner: Moku.system_runner) ⇒ Artifact

Returns a new instance of Artifact.

Parameters:

  • path (Pathname)

    The top-level directory under which to construct the artifact. This path should exist.

  • signature (ReleaseSignature)

    A signature identifying the references that should be used in the construction of this artifact.


28
29
30
31
32
# File 'lib/moku/artifact.rb', line 28

def initialize(path:, signature:, runner: Moku.system_runner)
  @path = path
  @signature = signature
  @runner = runner
end

Instance Attribute Details

#pathPathname (readonly)

The path of the top-level directory where this artifact is located.

Returns:

  • (Pathname)

36
37
38
# File 'lib/moku/artifact.rb', line 36

def path
  @path
end

Instance Method Details

#bundle_pathPathname

The path where gems are installed; created if it doesn't exist.

Returns:

  • (Pathname)

69
70
71
72
# File 'lib/moku/artifact.rb', line 69

def bundle_path
  @bundle_path ||= (path/"vendor"/"bundle"/"ruby"/gem_version)
    .tap(&:mkpath)
end

#devArchiveReference

This artifact's developer config

Returns:


47
# File 'lib/moku/artifact.rb', line 47

def_delegators :@signature, :source, :infrastructure, :dev

#gem_versionString

Get the gem version of the artifact's source, as specified by rbenv and as recognized by bundler's installation paths.

Returns:

  • (String)

60
61
62
63
64
65
# File 'lib/moku/artifact.rb', line 60

def gem_version
  return @gem_version if @gem_version

  major, minor, = run("rbenv local").output.strip.split(".")
  @gem_version = "#{major}.#{minor}.0"
end

#infrastructureArchiveReference

This artifact's infrastructure config

Returns:


47
# File 'lib/moku/artifact.rb', line 47

def_delegators :@signature, :source, :infrastructure, :dev

#run(command) ⇒ Status

Run the given command in the context of the artifact.

Returns:


51
52
53
54
55
# File 'lib/moku/artifact.rb', line 51

def run(command)
  with_env do
    runner.run("#{rbenv_env} #{command}")
  end
end

#sourceArchiveReference

This artifact's source

Returns:


47
# File 'lib/moku/artifact.rb', line 47

def_delegators :@signature, :source, :infrastructure, :dev