Class: Formulary::BottleLoader Private

Inherits:
FormulaLoader show all
Defined in:
Library/Homebrew/formulary.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.

Loads a formula from a bottle.

Instance Attribute Summary

Attributes inherited from FormulaLoader

#alias_path, #name, #path

Instance Method Summary collapse

Methods inherited from FormulaLoader

#klass

Methods included from Context

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

Constructor Details

#initialize(bottle_name) ⇒ BottleLoader

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


156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'Library/Homebrew/formulary.rb', line 156

def initialize(bottle_name)
  case bottle_name
  when URL_START_REGEX
    # 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 }
    resource.specs[:bottle] = true
    downloader = resource.downloader
    cached = downloader.cached_location.exist?
    downloader.fetch
    ohai "Pouring the cached bottle" if cached
    @bottle_filename = downloader.cached_location
  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, force_bottle: false, flags: []) ⇒ Object

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.


175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'Library/Homebrew/formulary.rb', line 175

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