Rename method to ::map_name_to_bottle
This commit is contained in:
parent
44bc942703
commit
75c1a23f63
@ -395,7 +395,7 @@ module Formulary
|
|||||||
)
|
)
|
||||||
raise ArgumentError, "Formulae must have a ref!" unless ref
|
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}"
|
cache_key = "#{ref}-#{spec}-#{alias_path}-#{from}"
|
||||||
if factory_cached? && cache[:formulary_factory] &&
|
if factory_cached? && cache[:formulary_factory] &&
|
||||||
@ -413,17 +413,18 @@ module Formulary
|
|||||||
formula
|
formula
|
||||||
end
|
end
|
||||||
|
|
||||||
# Register a reference mapping. This mapping will be used by {Formulary::factory}
|
# Map a formula name to a bottle archive. This mapping will be used by {Formulary::factory}
|
||||||
# to allow certain references to be substituted for another string before
|
# to allow formulae to be loaded automatically from their bottle archive without
|
||||||
# being retrived. For example, to map `foo` to the `bar` formula:
|
# needing to exist in a tap or be passed as a complete filepath. For example,
|
||||||
# <pre>Formulary.map "foo", to: "bar"
|
# to map `foo` to the `hello` formula from its bottle archive:
|
||||||
# Formulary.factory "bar" # returns the bar formula
|
# <pre>Formulary.map_name_to_bottle "foo", HOMEBREW_CACHE/"hello--2.10"
|
||||||
|
# Formulary.factory "foo" # returns the hello formula from the bottle archive
|
||||||
# </pre>
|
# </pre>
|
||||||
# @param ref the string to map.
|
# @param name the string to map.
|
||||||
# @param :to the target reference to which `ref` should be mapped.
|
# @param bottle a path pointing to the target bottle archive.
|
||||||
def self.map(ref, to:)
|
def self.map_name_to_bottle(name, bottle)
|
||||||
@ref_mappings ||= {}
|
@name_mappings ||= {}
|
||||||
@ref_mappings[ref] = to
|
@name_mappings[name] = bottle.realpath
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return a {Formula} instance for the given rack.
|
# Return a {Formula} instance for the given rack.
|
||||||
|
|||||||
@ -205,7 +205,7 @@ describe Formulary do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "::map" do
|
describe "::map_name_to_bottle" do
|
||||||
before do
|
before do
|
||||||
formula_path.dirname.mkpath
|
formula_path.dirname.mkpath
|
||||||
formula_path.write formula_content
|
formula_path.write formula_content
|
||||||
@ -216,7 +216,7 @@ describe Formulary do
|
|||||||
described_class.factory("formula-to-map")
|
described_class.factory("formula-to-map")
|
||||||
}.to raise_error(FormulaUnavailableError)
|
}.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)
|
expect(described_class.factory("formula-to-map")).to be_kind_of(Formula)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user