Class: AbstractDownloadStrategy

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
FileUtils
Defined in:
brew/Library/Homebrew/download_strategy.rb

Defined Under Namespace

Modules: Pourable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of AbstractDownloadStrategy



28
29
30
31
32
33
34
35
36
# File 'brew/Library/Homebrew/download_strategy.rb', line 28

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

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache



24
25
26
# File 'brew/Library/Homebrew/download_strategy.rb', line 24

def cache
  @cache
end

#cached_locationObject (readonly)

Returns the value of attribute cached_location



24
25
26
# File 'brew/Library/Homebrew/download_strategy.rb', line 24

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.



82
83
84
# File 'brew/Library/Homebrew/download_strategy.rb', line 82

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

#urlObject (readonly)

Returns the value of attribute url



24
25
26
# File 'brew/Library/Homebrew/download_strategy.rb', line 24

def url
  @url
end

Instance Method Details

#basenameObject



92
93
94
# File 'brew/Library/Homebrew/download_strategy.rb', line 92

def basename
  cached_location.basename
end

#clear_cacheObject

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



88
89
90
# File 'brew/Library/Homebrew/download_strategy.rb', line 88

def clear_cache
  rm_rf(cached_location)
end

#fetchObject

Download and cache the resource as #cached_location.



39
# File 'brew/Library/Homebrew/download_strategy.rb', line 39

def fetch; end

#ohai(*args) ⇒ Object



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

def ohai(*args)
  super(*args) unless shutup
end

#puts(*args) ⇒ Object



46
47
48
# File 'brew/Library/Homebrew/download_strategy.rb', line 46

def puts(*args)
  super(*args) unless shutup
end

#shutup!Object

Suppress output



42
43
44
# File 'brew/Library/Homebrew/download_strategy.rb', line 42

def shutup!
  @shutup = 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.



57
58
59
60
61
62
63
64
65
# File 'brew/Library/Homebrew/download_strategy.rb', line 57

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