Class: Formulary::BottleLoader

Inherits:
FormulaLoader show all
Defined in:
Library/Homebrew/formulary.rb

Overview

Loads formulae from bottles.

Instance Attribute Summary

Attributes inherited from FormulaLoader

#alias_path, #name, #path

Instance Method Summary collapse

Methods inherited from FormulaLoader

#klass

Constructor Details

#initialize(bottle_name) ⇒ BottleLoader



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'Library/Homebrew/formulary.rb', line 108

def initialize(bottle_name)
  case bottle_name
  when %r{(https?|ftp|file)://}
    # The name of the formula is found between the last slash and the last hyphen.
    formula_name = File.basename(bottle_name)[/(.+)-/, 1]
    resource = Resource.new(formula_name) { url bottle_name }
    downloader = CurlBottleDownloadStrategy.new resource.name, resource
    @bottle_filename = downloader.cached_location
    cached = @bottle_filename.exist?
    downloader.fetch
    ohai "Pouring the cached bottle" if cached
  else
    @bottle_filename = Pathname(bottle_name).realpath
  end
  name, full_name = Utils::Bottles.resolve_formula_names @bottle_filename
  super name, Formulary.path(full_name)
end

Instance Method Details

#get_formula(spec) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'Library/Homebrew/formulary.rb', line 126

def get_formula(spec, **)
  contents = Utils::Bottles.formula_contents @bottle_filename, name: name
  formula = begin
    Formulary.from_contents name, @bottle_filename, contents, spec
  rescue FormulaUnreadableError => e
    opoo <<~EOS
      Unreadable formula in #{@bottle_filename}:
      #{e}
    EOS
    super
  end
  formula.local_bottle_path = @bottle_filename
  formula
end