Class: VCSDownloadStrategy Abstract Private

Inherits:
AbstractDownloadStrategy show all
Defined in:
Library/Homebrew/download_strategy.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class is abstract.

Abstract superclass for all download strategies downloading from a version control system.

Constant Summary collapse

REF_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[:tag, :branch, :revisions, :revision].freeze

Instance Attribute Summary

Attributes inherited from AbstractDownloadStrategy

#cache, #cached_location, #source_modified_time, #url

Instance Method Summary collapse

Methods inherited from AbstractDownloadStrategy

#basename, #clear_cache, #shutup!, #stage

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

Constructor Details

#initialize(url, name, version, **meta) ⇒ VCSDownloadStrategy

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of VCSDownloadStrategy.


142
143
144
145
146
147
# File 'Library/Homebrew/download_strategy.rb', line 142

def initialize(url, name, version, **meta)
  super
  @ref_type, @ref = extract_ref(meta)
  @revision = meta[:revision]
  @cached_location = @cache/"#{name}--#{cache_tag}"
end

Instance Method Details

#commit_outdated?(commit) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

183
184
185
186
# File 'Library/Homebrew/download_strategy.rb', line 183

def commit_outdated?(commit)
  @last_commit ||= fetch_last_commit
  commit != @last_commit
end

#fetchObject

Download and cache the repository at AbstractDownloadStrategy#cached_location.


152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'Library/Homebrew/download_strategy.rb', line 152

def fetch
  ohai "Cloning #{url}"

  if cached_location.exist? && repo_valid?
    puts "Updating #{cached_location}"
    update
  elsif cached_location.exist?
    puts "Removing invalid repository from cache"
    clear_cache
    clone_repo
  else
    clone_repo
  end

  version.update_commit(last_commit) if head?

  return unless @ref_type == :tag
  return unless @revision && current_revision
  return if current_revision == @revision

  raise <<~EOS
    #{@ref} tag should be #{@revision}
    but is actually #{current_revision}
  EOS
end

#fetch_last_commitObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


178
179
180
181
# File 'Library/Homebrew/download_strategy.rb', line 178

def fetch_last_commit
  fetch
  last_commit
end

#head?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

188
189
190
# File 'Library/Homebrew/download_strategy.rb', line 188

def head?
  version.respond_to?(:head?) && version.head?
end

#last_commitObject

Return last commit's unique identifier for the repository. Return most recent modified timestamp unless overridden.


196
197
198
# File 'Library/Homebrew/download_strategy.rb', line 196

def last_commit
  source_modified_time.to_i.to_s
end