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

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

Overview

This class is abstract.

Subclass and override Capistrano::Distribution::Distributor::Abstract#distribute to create a distributor that extracts archives found on the local filesystem.

A convenience class for distributors that extract an archive file.

Direct Known Subclasses

AbstractCurl, Tar, Zip

Constant Summary collapse

EXT_MATCHER =

A regexp that matches file extentions typically found on archives used to distribute program binaries and source releases.

%r{(\.[^\d.]+[^.]*)+$}

Instance Attribute Summary collapse

Attributes inherited from Abstract

#context, #repo_id, #target, #url

Instance Method Summary collapse

Methods inherited from Abstract

#distribute, #release_path, #repo_path

Constructor Details

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

Returns a new instance of AbstractArchiver.

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):

  • :subtree (String)

    a path within the archive to extract as if its contents were at the root of the archive



28
29
30
31
32
33
# File 'lib/capistrano/distribution/distributor/abstract_archiver.rb', line 28

def initialize(context, url, opts = {})
  super(context, url, opts)
  @subtree = Pathname.new(
    opts.fetch(:subtree, File.basename(url).sub(ext_matcher, ''))
  )
end

Instance Attribute Details

#subtreeObject (readonly, private)

The path within the archive to extract. May be an empty string.



49
50
51
# File 'lib/capistrano/distribution/distributor/abstract_archiver.rb', line 49

def subtree
  @subtree
end

Instance Method Details

#checkBoolean

Tests whether or not the archive indicated by Capistrano::Distribution::Distributor::Abstract#url is locally available.

Returns:

  • (Boolean)

    true if the archive is available; otherwise, false.

See Also:



41
42
43
# File 'lib/capistrano/distribution/distributor/abstract_archiver.rb', line 41

def check
  context.test '[', '-f', url.path, ']'
end

#ext_matcherRegexp (private)

Returns a regexp that matches file extentions.

Returns:

  • (Regexp)

    a regexp that matches file extentions.



53
54
55
# File 'lib/capistrano/distribution/distributor/abstract_archiver.rb', line 53

def ext_matcher
  EXT_MATCHER
end