mirror of
https://github.com/Homebrew/brew.git
synced 2026-08-12 22:29:27 +04:00
Add Utils::convert_to_string_or_symbol
This commit is contained in:
@@ -171,7 +171,7 @@ module Homebrew
|
||||
files = hash.dig("bottle", "stable", "files") || {}
|
||||
files.map do |tag, bottle_spec|
|
||||
{
|
||||
cellar: Formulary.convert_to_string_or_symbol(bottle_spec.fetch("cellar")),
|
||||
cellar: Utils.convert_to_string_or_symbol(bottle_spec.fetch("cellar")),
|
||||
tag.to_sym => bottle_spec.fetch("sha256"),
|
||||
}
|
||||
end
|
||||
@@ -214,7 +214,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
if (keg_only_hash = hash["keg_only_reason"])
|
||||
reason = Formulary.convert_to_string_or_symbol(keg_only_hash.fetch("reason"))
|
||||
reason = Utils.convert_to_string_or_symbol(keg_only_hash.fetch("reason"))
|
||||
explanation = keg_only_hash["explanation"]
|
||||
hash["keg_only_args"] = [reason, explanation].compact
|
||||
end
|
||||
|
||||
@@ -467,13 +467,6 @@ module Formulary
|
||||
class_name
|
||||
end
|
||||
|
||||
sig { params(string: String).returns(T.any(String, Symbol)) }
|
||||
def self.convert_to_string_or_symbol(string)
|
||||
return T.must(string[1..]).to_sym if string.start_with?(":")
|
||||
|
||||
string
|
||||
end
|
||||
|
||||
# A {FormulaLoader} returns instances of formulae.
|
||||
# Subclasses implement loaders for particular sources of formulae.
|
||||
class FormulaLoader
|
||||
|
||||
@@ -748,16 +748,6 @@ RSpec.describe Formulary do
|
||||
end
|
||||
end
|
||||
|
||||
describe "::convert_to_string_or_symbol" do
|
||||
it "returns the original string if it doesn't start with a colon" do
|
||||
expect(described_class.convert_to_string_or_symbol("foo")).to eq "foo"
|
||||
end
|
||||
|
||||
it "returns a symbol if the original string starts with a colon" do
|
||||
expect(described_class.convert_to_string_or_symbol(":foo")).to eq :foo
|
||||
end
|
||||
end
|
||||
|
||||
describe "::loader_for" do
|
||||
context "when given a relative path with two slashes" do
|
||||
it "returns a `FromPathLoader`" do
|
||||
|
||||
@@ -117,4 +117,11 @@ RSpec.describe Utils do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".convert_to_string_or_symbol" do
|
||||
specify(:aggregate_failures) do
|
||||
expect(described_class.convert_to_string_or_symbol(":example")).to eq(:example)
|
||||
expect(described_class.convert_to_string_or_symbol("example")).to eq("example")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -220,4 +220,16 @@ module Utils
|
||||
def self.safe_filename(basename)
|
||||
basename.gsub(SAFE_FILENAME_REGEX, "")
|
||||
end
|
||||
|
||||
# Converts a string starting with `:` to a symbol, otherwise returns the
|
||||
# string itself.
|
||||
#
|
||||
# convert_to_string_or_symbol(":example") # => :example
|
||||
# convert_to_string_or_symbol("example") # => "example"
|
||||
sig { params(string: String).returns(T.any(String, Symbol)) }
|
||||
def self.convert_to_string_or_symbol(string)
|
||||
return T.must(string[1..]).to_sym if string.start_with?(":")
|
||||
|
||||
string
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user