Class: AbstractDownloadStrategy Abstract Private

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

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 SystemCommand::Mixin

#system_command, #system_command!

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



56
57
58
59
60
61
62
63
64
# File 'download_strategy.rb', line 56

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



52
53
54
# File 'download_strategy.rb', line 52

def cache
  @cache
end

#cached_locationPathname (readonly)

Location of the cached download.

Returns:



50
51
52
# File 'download_strategy.rb', line 50

def cached_location
  @cached_location
end

#urlString (readonly)

The download URL.

Returns:



44
45
46
# File 'download_strategy.rb', line 44

def url
  @url
end

Instance Method Details

#basenameObject

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.



142
143
144
# File 'download_strategy.rb', line 142

def basename
  cached_location.basename
end

#clear_cacheObject

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



138
139
140
# File 'download_strategy.rb', line 138

def clear_cache
  rm_rf(cached_location)
end

#fetch(timeout: nil) ⇒ Object

Download and cache the resource at #cached_location.



69
# File 'download_strategy.rb', line 69

def fetch(timeout: nil); end

#quiet!void

This method returns an undefined value.

Disable any output during downloading.



75
76
77
# File 'download_strategy.rb', line 75

def quiet!
  @quiet = true
end

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

Returns:

  • (Boolean)


86
87
88
# File 'download_strategy.rb', line 86

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

#shutup!void

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.

Deprecated.

Use #quiet! instead.

This method returns an undefined value.

Disable any output during downloading.



81
82
83
84
# File 'download_strategy.rb', line 81

def shutup!
  odisabled "`AbstractDownloadStrategy#shutup!`", "`AbstractDownloadStrategy#quiet!`"
  quiet!
end

#source_modified_timeTime

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

Returns:



130
131
132
# File 'download_strategy.rb', line 130

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

#stage(&block) ⇒ Object

Unpack #cached_location into the current working directory.

Additionally, if a block is given, the working directory was previously empty and a single directory is extracted from the archive, the block will be called with the working directory changed to that directory. Otherwise this method will return, or the block will be called, without changing the current working directory.



99
100
101
102
103
104
105
106
107
# File 'download_strategy.rb', line 99

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