Class: AbstractDownloadStrategy Abstract Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Context, FileUtils
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.

Defined Under Namespace

Modules: Pourable

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Context

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

Constructor Details

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

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 AbstractDownloadStrategy.


38
39
40
41
42
43
44
45
46
# File 'Library/Homebrew/download_strategy.rb', line 38

def initialize(url, name, version, **meta)
  @url = url
  @name = name
  @version = version
  @cache = meta.fetch(:cache, HOMEBREW_CACHE)
  @meta = meta
  @quiet = false
  extend Pourable if meta[:bottle]
end

Instance Attribute Details

#cacheObject (readonly)

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.


34
35
36
# File 'Library/Homebrew/download_strategy.rb', line 34

def cache
  @cache
end

#cached_locationObject (readonly)

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.


34
35
36
# File 'Library/Homebrew/download_strategy.rb', line 34

def cached_location
  @cached_location
end

#source_modified_timeObject (readonly)

Returns the most recent modified time for all files in the current working directory after stage.


98
99
100
# File 'Library/Homebrew/download_strategy.rb', line 98

def source_modified_time
  Pathname.pwd.to_enum(:find).select(&:file?).map(&:mtime).max
end

#urlObject (readonly)

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.


34
35
36
# File 'Library/Homebrew/download_strategy.rb', line 34

def url
  @url
end

Instance Method Details

#basenameObject

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.


110
111
112
# File 'Library/Homebrew/download_strategy.rb', line 110

def basename
  cached_location.basename
end

#clear_cacheObject

Remove #cached_location and any other files associated with the resource from the cache.


106
107
108
# File 'Library/Homebrew/download_strategy.rb', line 106

def clear_cache
  rm_rf(cached_location)
end

#fetchObject

Download and cache the resource at #cached_location.


51
# File 'Library/Homebrew/download_strategy.rb', line 51

def fetch; end

#quiet?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)

62
63
64
# File 'Library/Homebrew/download_strategy.rb', line 62

def quiet?
  Context.current.quiet? || @quiet
end

#shutup!Object

Disable any output during downloading.

TODO: Deprecate once we have an explicitly documented alternative.


58
59
60
# File 'Library/Homebrew/download_strategy.rb', line 58

def shutup!
  @quiet = true
end

#stageObject

Unpack #cached_location into the current working directory, and possibly chdir into the newly-unpacked directory. Unlike Resource#stage, this does not take a block.


71
72
73
74
75
76
77
78
79
# File 'Library/Homebrew/download_strategy.rb', line 71

def stage
  UnpackStrategy.detect(cached_location,
                        prioritise_extension: true,
                        ref_type: @ref_type, ref: @ref)
                .extract_nestedly(basename:             basename,
                                  prioritise_extension: true,
                                  verbose:              verbose? && !quiet?)
  chdir
end