Normalize service serialization method names

This commit is contained in:
apainintheneck 2024-01-30 23:07:19 -08:00 committed by Patrick Linnane
parent d9a98ac4ec
commit 3c503cdf56
No known key found for this signature in database
5 changed files with 16 additions and 16 deletions

View File

@ -2255,7 +2255,7 @@ class Formula
"disable_date" => disable_date, "disable_date" => disable_date,
"disable_reason" => disable_reason, "disable_reason" => disable_reason,
"post_install_defined" => post_install_defined?, "post_install_defined" => post_install_defined?,
"service" => (service.serialize if service?), "service" => (service.to_hash if service?),
"tap_git_head" => tap_git_head, "tap_git_head" => tap_git_head,
"ruby_source_path" => ruby_source_path, "ruby_source_path" => ruby_source_path,
"ruby_source_checksum" => {}, "ruby_source_checksum" => {},
@ -2318,7 +2318,7 @@ class Formula
api_hash["pour_bottle_only_if"] = self.class.pour_bottle_only_if.to_s if self.class.pour_bottle_only_if api_hash["pour_bottle_only_if"] = self.class.pour_bottle_only_if.to_s if self.class.pour_bottle_only_if
api_hash["link_overwrite"] = self.class.link_overwrite_paths.to_a if self.class.link_overwrite_paths.present? api_hash["link_overwrite"] = self.class.link_overwrite_paths.to_a if self.class.link_overwrite_paths.present?
api_hash["caveats"] = caveats_with_placeholders if caveats api_hash["caveats"] = caveats_with_placeholders if caveats
api_hash["service"] = service.serialize if service? api_hash["service"] = service.to_hash if service?
if stable if stable
api_hash["version"] = stable&.version&.to_s api_hash["version"] = stable&.version&.to_s

View File

@ -341,7 +341,7 @@ module Formulary
end end
if (service_hash = json_formula["service"].presence) if (service_hash = json_formula["service"].presence)
service_hash = Homebrew::Service.deserialize(service_hash) service_hash = Homebrew::Service.from_hash(service_hash)
service do service do
T.bind(self, Homebrew::Service) T.bind(self, Homebrew::Service)

View File

@ -515,7 +515,7 @@ module Homebrew
# Prepare the service hash for inclusion in the formula API JSON. # Prepare the service hash for inclusion in the formula API JSON.
sig { returns(Hash) } sig { returns(Hash) }
def serialize def to_hash
name_params = { name_params = {
macos: (plist_name if plist_name != default_plist_name), macos: (plist_name if plist_name != default_plist_name),
linux: (service_name if service_name != default_service_name), linux: (service_name if service_name != default_service_name),
@ -568,7 +568,7 @@ module Homebrew
# Turn the service API hash values back into what is expected by the formula DSL. # Turn the service API hash values back into what is expected by the formula DSL.
sig { params(api_hash: Hash).returns(Hash) } sig { params(api_hash: Hash).returns(Hash) }
def self.deserialize(api_hash) def self.from_hash(api_hash)
hash = {} hash = {}
hash[:name] = api_hash["name"].transform_keys(&:to_sym) if api_hash.key?("name") hash[:name] = api_hash["name"].transform_keys(&:to_sym) if api_hash.key?("name")

View File

@ -738,7 +738,7 @@ describe Formula do
url "https://brew.sh/test-1.0.tbz" url "https://brew.sh/test-1.0.tbz"
end end
expect(f.service.serialize).to eq({}) expect(f.service.to_hash).to eq({})
end end
specify "service complicated" do specify "service complicated" do
@ -754,7 +754,7 @@ describe Formula do
keep_alive true keep_alive true
end end
end end
expect(f.service.serialize.keys) expect(f.service.to_hash.keys)
.to contain_exactly(:run, :run_type, :error_log_path, :log_path, :working_dir, :keep_alive) .to contain_exactly(:run, :run_type, :error_log_path, :log_path, :working_dir, :keep_alive)
end end
@ -766,7 +766,7 @@ describe Formula do
end end
end end
expect(f.service.serialize.keys).to contain_exactly(:run, :run_type) expect(f.service.to_hash.keys).to contain_exactly(:run, :run_type)
end end
specify "service with only custom names" do specify "service with only custom names" do
@ -779,7 +779,7 @@ describe Formula do
expect(f.plist_name).to eq("custom.macos.beanstalkd") expect(f.plist_name).to eq("custom.macos.beanstalkd")
expect(f.service_name).to eq("custom.linux.beanstalkd") expect(f.service_name).to eq("custom.linux.beanstalkd")
expect(f.service.serialize.keys).to contain_exactly(:name) expect(f.service.to_hash.keys).to contain_exactly(:name)
end end
specify "service helpers return data" do specify "service helpers return data" do

View File

@ -1044,7 +1044,7 @@ describe Homebrew::Service do
end end
end end
describe "#serialize" do describe "#to_hash" do
let(:serialized_hash) do let(:serialized_hash) do
{ {
environment_variables: { environment_variables: {
@ -1072,12 +1072,12 @@ describe Homebrew::Service do
end end
Formula.generating_hash! Formula.generating_hash!
expect(f.service.serialize).to eq(serialized_hash) expect(f.service.to_hash).to eq(serialized_hash)
Formula.generated_hash! Formula.generated_hash!
end end
end end
describe ".deserialize" do describe ".from_hash" do
let(:serialized_hash) do let(:serialized_hash) do
{ {
"name" => { "name" => {
@ -1111,12 +1111,12 @@ describe Homebrew::Service do
end end
it "replaces placeholders with local paths" do it "replaces placeholders with local paths" do
expect(described_class.deserialize(serialized_hash)).to eq(deserialized_hash) expect(described_class.from_hash(serialized_hash)).to eq(deserialized_hash)
end end
describe "run command" do describe "run command" do
it "handles String argument correctly" do it "handles String argument correctly" do
expect(described_class.deserialize({ expect(described_class.from_hash({
"run" => "$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd", "run" => "$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd",
})).to eq({ })).to eq({
run: "#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd", run: "#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd",
@ -1124,7 +1124,7 @@ describe Homebrew::Service do
end end
it "handles Array argument correctly" do it "handles Array argument correctly" do
expect(described_class.deserialize({ expect(described_class.from_hash({
"run" => ["$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd", "--option"], "run" => ["$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd", "--option"],
})).to eq({ })).to eq({
run: ["#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd", "--option"], run: ["#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd", "--option"],
@ -1132,7 +1132,7 @@ describe Homebrew::Service do
end end
it "handles Hash argument correctly" do it "handles Hash argument correctly" do
expect(described_class.deserialize({ expect(described_class.from_hash({
"run" => { "run" => {
"linux" => "$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd", "linux" => "$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd",
"macos" => ["$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd", "--option"], "macos" => ["$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd", "--option"],