Rename method to ::map_name_to_bottle

This commit is contained in:
Rylan Polster 2021-06-15 11:21:59 -04:00
parent 44bc942703
commit 75c1a23f63
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
2 changed files with 14 additions and 13 deletions

View File

@ -395,7 +395,7 @@ module Formulary
)
raise ArgumentError, "Formulae must have a ref!" unless ref
ref = @ref_mappings[ref] if @ref_mappings.present? && @ref_mappings.key?(ref)
ref = @name_mappings[ref] if @name_mappings.present? && @name_mappings.key?(ref)
cache_key = "#{ref}-#{spec}-#{alias_path}-#{from}"
if factory_cached? && cache[:formulary_factory] &&
@ -413,17 +413,18 @@ module Formulary
formula
end
# Register a reference mapping. This mapping will be used by {Formulary::factory}
# to allow certain references to be substituted for another string before
# being retrived. For example, to map `foo` to the `bar` formula:
# <pre>Formulary.map "foo", to: "bar"
# Formulary.factory "bar" # returns the bar formula
# Map a formula name to a bottle archive. This mapping will be used by {Formulary::factory}
# to allow formulae to be loaded automatically from their bottle archive without
# needing to exist in a tap or be passed as a complete filepath. For example,
# to map `foo` to the `hello` formula from its bottle archive:
# <pre>Formulary.map_name_to_bottle "foo", HOMEBREW_CACHE/"hello--2.10"
# Formulary.factory "foo" # returns the hello formula from the bottle archive
# </pre>
# @param ref the string to map.
# @param :to the target reference to which `ref` should be mapped.
def self.map(ref, to:)
@ref_mappings ||= {}
@ref_mappings[ref] = to
# @param name the string to map.
# @param bottle a path pointing to the target bottle archive.
def self.map_name_to_bottle(name, bottle)
@name_mappings ||= {}
@name_mappings[name] = bottle.realpath
end
# Return a {Formula} instance for the given rack.

View File

@ -205,7 +205,7 @@ describe Formulary do
end
end
describe "::map" do
describe "::map_name_to_bottle" do
before do
formula_path.dirname.mkpath
formula_path.write formula_content
@ -216,7 +216,7 @@ describe Formulary do
described_class.factory("formula-to-map")
}.to raise_error(FormulaUnavailableError)
described_class.map "formula-to-map", to: formula_name
described_class.map_name_to_bottle "formula-to-map", formula_path
expect(described_class.factory("formula-to-map")).to be_kind_of(Formula)
end