class Omnibus::Fetcher

Attributes

build_dir[R]
described_version[R]

The upstream version as described before resolution.

@return [String]

This will usually be the same as resolved_version but may refer toa remote ref name or tag for a source such as git.

name[R]

The name of the software this fetcher shall fetch

@return [String]

project_dir[R]

The path where fetched software should live.

Only files under this directory are modified. If the source to fetch is a directory, it is staged rooted here. If it’s a file, it’s copied underneath this directory. If it’s a tarball, it’s extracted here. If it’s a repo, its checkout is rooted here. You get the idea.

It’s named project_dir instead of extract_dir/extract_path because of legacy reasons. This has nothing to do with project definitions or the underlying relative_path for a software definition (except for legacy behavior).

@return [String]

resolved_version[R]

The exact upstream version that a fetcher should fetch.

@return [String]

For sources that allow aliases (branch name, tags, etc). Users should use the class method resolve_version to determine this before constructing a fetcher.

source[R]

The source for this fetcher.

@return [Hash]

Public Class Methods

new(manifest_entry, project_dir, build_dir) click to toggle source

Create a new Fetcher object from the given software.

The parameters correspond to the relevant portions of a software definition that a fetcher needs access to. This avoids strongly coupling the software object with all fetchers.

@param [ManifestEntry] manifest_entry @param [String] project_dir @param [String] build_dir

# File lib/omnibus/fetcher.rb, line 86
def initialize(manifest_entry, project_dir, build_dir)
  @name    = manifest_entry.name
  @source  = manifest_entry.locked_source
  @resolved_version = manifest_entry.locked_version
  @described_version = manifest_entry.described_version
  @project_dir = project_dir
  @build_dir = build_dir
end

Private Class Methods

fetcher_class_for_source(source) click to toggle source
# File lib/omnibus/fetcher.rb, line 188
def self.fetcher_class_for_source(source)
  if source
    if source[:url]
      NetFetcher
    elsif source[:git]
      GitFetcher
    elsif source[:path]
      PathFetcher
    elsif source[:file]
      FileFetcher
    end
  else
    NullFetcher
  end
end
resolve_version(version, source) click to toggle source

Class Methods

# File lib/omnibus/fetcher.rb, line 184
def self.resolve_version(version, source)
  fetcher_class_for_source(source).resolve_version(version, source)
end

Public Instance Methods

clean() click to toggle source

@abstract

# File lib/omnibus/fetcher.rb, line 112
def clean
  raise NotImplementedError
end
fetch() click to toggle source

@abstract

# File lib/omnibus/fetcher.rb, line 119
def fetch
  raise NotImplementedError
end
fetch_required?() click to toggle source

@abstract

# File lib/omnibus/fetcher.rb, line 105
def fetch_required?
  raise NotImplementedError
end
fetcher() click to toggle source

@!endgroup


# File lib/omnibus/fetcher.rb, line 141
def fetcher
  self
end
version() click to toggle source

All fetchers should prefer resolved_version to version this is provided for compatibility.

# File lib/omnibus/fetcher.rb, line 149
def version
  resolved_version
end
version_for_cache() click to toggle source

@abstract

# File lib/omnibus/fetcher.rb, line 133
def version_for_cache
  raise NotImplementedError
end
version_guid() click to toggle source

@abstract

# File lib/omnibus/fetcher.rb, line 126
def version_guid
  raise NotImplementedError
end

Private Instance Methods

create_required_directories() click to toggle source

Idempotently create the required directories for building/downloading. Fetchers should call this method before performing any operations that manipulate the filesystem.

@return [void]

# File lib/omnibus/fetcher.rb, line 172
def create_required_directories
  [
    Config.cache_dir,
    Config.source_dir,
    build_dir,
    project_dir,
  ].each do |directory|
    FileUtils.mkdir_p(directory) unless File.directory?(directory)
  end
end
log_key() click to toggle source

Override the log_key for this fetcher to include the name of the software during the fetch.

@return [String]

# File lib/omnibus/fetcher.rb, line 161
def log_key
  @log_key ||= "#{super}: #{name}"
end