Class: Capistrano::Distribution::Distributor::Abstract Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/distribution/distributor/abstract.rb

Overview

This class is abstract.

Subclass and override #check and #distribute to create a distributor.

An abstract distributor upon which all distributors should ultimately be based.

See the existing concrete distributor definitions for examples.

Direct Known Subclasses

AbstractArchiver, AbstractGit

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, url, opts = {}) ⇒ Abstract

Returns a new instance of Abstract.

Parameters:

  • context ((#test, #execute))

    a Capistrano context used to run commands.

  • url (URI, String)

    a URL to be used for fetching the artifact to be distributed

  • opts (Hash) (defaults to: {})

    options to override default settings

Options Hash (opts):

  • :target (String) — default: ''

    a path within the release area to be the root of the distribution.



22
23
24
25
26
27
28
# File 'lib/capistrano/distribution/distributor/abstract.rb', line 22

def initialize(context, url, opts = {})
  @context = context
  @url = URI === url ? url : URI.parse(url)
  @target = opts.fetch(:target, '')

  @repo_id = Digest::SHA1.hexdigest(url.to_s)
end

Instance Attribute Details

#contextObject (readonly, private)

The Capistrano context in which the distributor will operate.



58
59
60
# File 'lib/capistrano/distribution/distributor/abstract.rb', line 58

def context
  @context
end

#repo_idObject (readonly, private)

A unique identifier for the distributor for use under #repo_path.



62
63
64
# File 'lib/capistrano/distribution/distributor/abstract.rb', line 62

def repo_id
  @repo_id
end

#targetObject (readonly, private)

A path relative to the release location in which to distribute the artifact.



66
67
68
# File 'lib/capistrano/distribution/distributor/abstract.rb', line 66

def target
  @target
end

#urlObject (readonly, private)

The source URL for the artifact to be distributed.



54
55
56
# File 'lib/capistrano/distribution/distributor/abstract.rb', line 54

def url
  @url
end

Instance Method Details

#checkBoolean

This method is abstract.

Override to provide a meaningful check for prerequisites during deployment.

Returns true when prerequisites are met and false otherwise.

Returns:

  • (Boolean)

    true when prerequisites are met and false otherwise.



36
37
38
# File 'lib/capistrano/distribution/distributor/abstract.rb', line 36

def check
  false
end

#distributenil

This method is abstract.

Override to provide meaningful distribution logic during deployment.

Returns:

  • (nil)

Raises:

  • (exception)

    when distribution fails.



47
48
# File 'lib/capistrano/distribution/distributor/abstract.rb', line 47

def distribute
end

#release_pathPathname (private)

Returns a path to the release location in which to distribute the artifact based on #target.

Returns:

  • (Pathname)

    a path to the release location in which to distribute the artifact based on #target



71
72
73
# File 'lib/capistrano/distribution/distributor/abstract.rb', line 71

def release_path
  context.release_path.join(target)
end

#repo_pathPathname (private)

Returns a path under the repo location to a unique workspace for the distributor.

Returns:

  • (Pathname)

    a path under the repo location to a unique workspace for the distributor



78
79
80
# File 'lib/capistrano/distribution/distributor/abstract.rb', line 78

def repo_path
  context.repo_path.join(repo_id)
end