Module: Capistrano::Distribution::Distributor
- Defined in:
- lib/capistrano/distribution/distributor.rb,
lib/capistrano/distribution/distributor/tar.rb,
lib/capistrano/distribution/distributor/zip.rb,
lib/capistrano/distribution/distributor/abstract.rb,
lib/capistrano/distribution/distributor/curl_tar.rb,
lib/capistrano/distribution/distributor/curl_zip.rb,
lib/capistrano/distribution/distributor/git_pull.rb,
lib/capistrano/distribution/distributor/git_push.rb,
lib/capistrano/distribution/distributor/tar_helper.rb,
lib/capistrano/distribution/distributor/abstract_git.rb,
lib/capistrano/distribution/distributor/abstract_curl.rb,
lib/capistrano/distribution/distributor/abstract_archiver.rb
Overview
This module is a factory for creating distributor objects that are able to fetch distributable artifacts from various sources and deploy them to a target host.
Defined Under Namespace
Modules: TarHelper Classes: Abstract, AbstractArchiver, AbstractCurl, AbstractGit, CurlTar, CurlZip, GitPull, GitPush, Tar, Zip
Class Method Summary collapse
-
.constantize(type) ⇒ Object
private
Finds the class to use for a distributor given a Symbol.
-
.create(context, definition) ⇒ Object
Create a concrete distributor object based on definition.
-
.type_from_url(url) ⇒ Symbol
private
Return a distributor type based on url.
Class Method Details
.constantize(type) ⇒ Object (private)
Finds the class to use for a distributor given a Symbol.
95 96 97 98 |
# File 'lib/capistrano/distribution/distributor.rb', line 95 def self.constantize(type) require "capistrano/distribution/distributor/#{type}" const_get(type.to_s.split('_').map(&:capitalize).join) end |
.create(context, definition) ⇒ Object
Create a concrete distributor object based on definition.
When definition is a String, it is assumed to be a URL that is used to guess about the type of distributor to create. For instance, URLs that end with ‘.git` will elicit the Git::Pull distributor. A URL without a scheme and ending with .tgz will elicit the Tar distributor.
When definition is an Array and the first element is a String, the distributor class is guessed using that String as in the case when definition is simply a String itself. The remaining members of the array are passed to the selected class’ initializer as arguments.
When definition is an Array and the first element is a Symbol, the Symbol is assumed to map to the class of the distributor to instantiate. The Symbol :curl_tar maps to the Curl::Tar distributor for example. The remaining members of the array are passed to the selected class’ initializer as arguments.
When definition is anything else, it is returned directly under the assumption that the configuration explicitly created a distributor.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/capistrano/distribution/distributor.rb', line 40 def self.create(context, definition) case definition when String type = type_from_url(definition) constantize(type).new(context, definition) when Array if Symbol === definition.first type, *args = definition else type = type_from_url(definition.first) args = definition end constantize(type).new(context, *args) else definition end end |
.type_from_url(url) ⇒ Symbol (private)
Return a distributor type based on url.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/capistrano/distribution/distributor.rb', line 67 def self.type_from_url(url) url = URI.parse(url.to_s) type = if url.scheme == 'git' || url.path =~ %r{\.git$} :git_pull elsif url.scheme.nil? || url.scheme == 'file' if url.path =~ %r{\.(tar(\.(gz|bzip2))?|tgz|tbz2)$}i :tar elsif url.path =~ %r{\.zip$}i :zip end elsif url.path =~ %r{\.(tar(\.(gz|bzip2))?|tgz|tbz2)$}i :curl_tar elsif url.path =~ %r{\.zip$}i :curl_zip end raise "Unable to guess distributor type for URL: #{url}" if type.nil? type end |