class GitCompound::Component::Source

Component source

Attributes

options[R]
origin[R]
repository[R]
version[R]

Public Class Methods

new(origin, version, strategy, options, component) click to toggle source
# File lib/git_compound/component/source.rb, line 12
def initialize(origin, version, strategy, options, component)
  raise CompoundSyntaxError, 'Source cannot be empty' if
    origin.nil? || origin.empty?

  @origin     = origin
  @strategy   = strategy
  @options    = options
  @component  = component
  @repository = Repository.factory(@origin)
  @version    = strategy.new(@repository, version)
end

Public Instance Methods

clone(destination) click to toggle source
# File lib/git_compound/component/source.rb, line 36
def clone(destination)
  @repository.clone(destination, clone_args)
end
manifest() click to toggle source

Loads manifest from source repository

# File lib/git_compound/component/source.rb, line 26
def manifest
  raise DependencyError,
        "Version #{@version} unreachable" unless @version.reachable?

  contents = @repository.files_contents(Manifest::FILENAMES, @version.ref)
  Manifest.new(contents, @component)
rescue FileNotFoundError
  Manifest.new(nil, @component)
end

Private Instance Methods

clone_args() click to toggle source
# File lib/git_compound/component/source.rb, line 42
def clone_args
  raise CompoundSyntaxError,
        '`shallow` keyword not available for sha version strategy' if
    @options.include?(:shallow) && @strategy == Component::Version::SHA

  opts = []
  opts << "--branch '#{@version.ref}' --depth 1" if @options.include? :shallow
  opts.join(' ')
end