Class: Vanagon::Component::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/vanagon/component/source.rb,
lib/vanagon/component/source/git.rb,
lib/vanagon/component/source/http.rb,
lib/vanagon/component/source/local.rb,
lib/vanagon/component/source/rewrite.rb

Defined Under Namespace

Classes: Git, Http, Local, Rewrite

Constant Summary collapse

SUPPORTED_PROTOCOLS =
%w[file http https git].freeze

Class Method Summary collapse

Class Method Details

.source(uri, **options) ⇒ Vanagon::Component::Source

Basic factory to hand back the correct Vanagon::Component::Source subtype to the component

Parameters:

  • url (String)

    URI of the source file (includes git@… style links)

  • options (Hash)

    hash of the options needed for the subtype

  • workdir (String)

    working directory to fetch the source into

Returns:

Raises:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vanagon/component/source.rb', line 18

def source(uri, **options)
  # First we try git
  if Vanagon::Component::Source::Git.valid_remote?(uri)
    return Vanagon::Component::Source::Git.new uri,
      sum: options[:sum],
      ref: options[:ref],
      workdir: options[:workdir]
  end

  # Then we try HTTP
  if Vanagon::Component::Source::Http.valid_url?(uri)
    return Vanagon::Component::Source::Http.new uri,
      sum: options[:sum],
      workdir: options[:workdir],
      # Default sum_type is md5 if unspecified:
      sum_type: options[:sum_type] || "md5"
  end

  # Then we try local
  if Vanagon::Component::Source::Local.valid_file?(uri)
    return Vanagon::Component::Source::Local.new uri,
      workdir: options[:workdir]
  end

  # Failing all of that, we give up
  raise Vanagon::Error,
    "Unknown file type: '#{uri}'; cannot continue"
end