Class: AbstractDownloadStrategy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FileUtils

#make, mkdir, mktemp, #old_mkdir, #old_ruby, #ruby, #scons, #xcodebuild

Constructor Details

#initialize(name, resource) ⇒ AbstractDownloadStrategy

Returns a new instance of AbstractDownloadStrategy



12
13
14
15
16
17
18
# File 'Library/Homebrew/download_strategy.rb', line 12

def initialize(name, resource)
  @name = name
  @resource = resource
  @url = resource.url
  @version = resource.version
  @meta = resource.specs
end

Instance Attribute Details

#cached_locationObject (readonly)

The path to the cached file or directory associated with the resource.



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

def cached_location; end

#metaObject (readonly)

Returns the value of attribute meta



9
10
11
# File 'Library/Homebrew/download_strategy.rb', line 9

def meta
  @meta
end

#nameObject (readonly)

Returns the value of attribute name



9
10
11
# File 'Library/Homebrew/download_strategy.rb', line 9

def name
  @name
end

#resourceObject (readonly)

Returns the value of attribute resource



9
10
11
# File 'Library/Homebrew/download_strategy.rb', line 9

def resource
  @resource
end

#shutupObject (readonly)

Returns the value of attribute shutup



10
11
12
# File 'Library/Homebrew/download_strategy.rb', line 10

def shutup
  @shutup
end

#versionObject (readonly)

Returns the value of attribute version



9
10
11
# File 'Library/Homebrew/download_strategy.rb', line 9

def version
  @version
end

Instance Method Details

#clear_cacheObject

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



53
54
55
# File 'Library/Homebrew/download_strategy.rb', line 53

def clear_cache
  rm_rf(cached_location)
end

#expand_safe_system_args(args) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'Library/Homebrew/download_strategy.rb', line 57

def expand_safe_system_args(args)
  args = args.dup
  args.each_with_index do |arg, ii|
    next unless arg.is_a? Hash
    if ARGV.verbose?
      args.delete_at ii
    else
      args[ii] = arg[:quiet_flag]
    end
    return args
  end
  # 2 as default because commands are eg. svn up, git pull
  args.insert(2, "-q") unless ARGV.verbose?
  args
end

#fetchObject

Download and cache the resource as #cached_location.



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

def fetch; end

#ohai(*args) ⇒ Object



32
33
34
# File 'Library/Homebrew/download_strategy.rb', line 32

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

#puts(*args) ⇒ Object



28
29
30
# File 'Library/Homebrew/download_strategy.rb', line 28

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

#quiet_safe_system(*args) ⇒ Object



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

def quiet_safe_system(*args)
  safe_system(*expand_safe_system_args(args))
end

#safe_system(*args) ⇒ Object



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

def safe_system(*args)
  if @shutup
    quiet_system(*args) || raise(ErrorDuringExecution.new(args.shift, *args))
  else
    super(*args)
  end
end

#shutup!Object

Suppress output



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

def shutup!
  @shutup = true
end

#source_modified_timeObject



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

def source_modified_time
  Pathname.pwd.to_enum(:find).select(&:file?).map(&:mtime).max
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.



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

def stage; end