Class: VCSDownloadStrategy Abstract Private
- Inherits:
-
AbstractDownloadStrategy
- Object
- AbstractDownloadStrategy
- VCSDownloadStrategy
- Defined in:
- download_strategy.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Abstract superclass for all download strategies downloading from a version control system.
Direct Known Subclasses
BazaarDownloadStrategy, CVSDownloadStrategy, FossilDownloadStrategy, GitDownloadStrategy, MercurialDownloadStrategy, SubversionDownloadStrategy
Constant Summary collapse
- REF_TYPES =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
[:tag, :branch, :revisions, :revision].freeze
Instance Attribute Summary collapse
-
#last_commit ⇒ String
readonly
Return last commit’s unique identifier for the repository.
Attributes inherited from AbstractDownloadStrategy
#cache, #cached_location, #source_modified_time, #url
Instance Method Summary collapse
-
#commit_outdated?(commit) ⇒ Boolean
private
-
#fetch(timeout: nil) ⇒ Object
Download and cache the repository at AbstractDownloadStrategy#cached_location.
-
#fetch_last_commit ⇒ Object
private
-
#head? ⇒ Boolean
private
-
#initialize(url, name, version, **meta) ⇒ VCSDownloadStrategy
constructor
private
A new instance of VCSDownloadStrategy.
Methods inherited from AbstractDownloadStrategy
#basename, #clear_cache, #quiet!, #quiet?, #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. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Returns a new instance of VCSDownloadStrategy.
196 197 198 199 200 201 |
# File 'download_strategy.rb', line 196 def initialize(url, name, version, **) super @ref_type, @ref = extract_ref() @revision = [:revision] @cached_location = @cache/"#{name}--#{cache_tag}" end |
Instance Attribute Details
#last_commit ⇒ String (readonly)
Return last commit’s unique identifier for the repository. Return most recent modified timestamp unless overridden.
252 253 254 |
# File 'download_strategy.rb', line 252 def last_commit source_modified_time.to_i.to_s end |
Instance Method Details
#commit_outdated?(commit) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
237 238 239 240 |
# File 'download_strategy.rb', line 237 def commit_outdated?(commit) @last_commit ||= fetch_last_commit commit != @last_commit end |
#fetch(timeout: nil) ⇒ Object
Download and cache the repository at AbstractDownloadStrategy#cached_location.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'download_strategy.rb', line 206 def fetch(timeout: nil) end_time = Time.now + timeout if timeout ohai "Cloning #{url}" if cached_location.exist? && repo_valid? puts "Updating #{cached_location}" update(timeout: end_time) elsif cached_location.exist? puts "Removing invalid repository from cache" clear_cache clone_repo(timeout: end_time) else clone_repo(timeout: end_time) end version.update_commit(last_commit) if head? return if @ref_type != :tag || @revision.blank? || current_revision.blank? || current_revision == @revision raise <<~EOS #{@ref} tag should be #{@revision} but is actually #{current_revision} EOS end |
#fetch_last_commit ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
232 233 234 235 |
# File 'download_strategy.rb', line 232 def fetch_last_commit fetch last_commit end |
#head? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
242 243 244 |
# File 'download_strategy.rb', line 242 def head? version.respond_to?(:head?) && version.head? end |