From 75c1a23f631dd820a328a98c53fc951202a91211 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Tue, 15 Jun 2021 11:21:59 -0400 Subject: [PATCH] Rename method to `::map_name_to_bottle` --- Library/Homebrew/formulary.rb | 23 ++++++++++++----------- Library/Homebrew/test/formulary_spec.rb | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index a902e92820..d3e7019045 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -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: - #
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:
+  # 
Formulary.map_name_to_bottle "foo", HOMEBREW_CACHE/"hello--2.10"
+  # Formulary.factory "foo" # returns the hello formula from the bottle archive
   # 
- # @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. diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index e6a0a95934..e9f750a4b9 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -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