From 3c503cdf563d93de6940878d4915270cf93d308d Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Tue, 30 Jan 2024 23:07:19 -0800 Subject: [PATCH] Normalize service serialization method names --- Library/Homebrew/formula.rb | 4 ++-- Library/Homebrew/formulary.rb | 2 +- Library/Homebrew/service.rb | 4 ++-- Library/Homebrew/test/formula_spec.rb | 8 ++++---- Library/Homebrew/test/service_spec.rb | 14 +++++++------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 6e5faeec9160a..6fb60ee81d8e1 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -2255,7 +2255,7 @@ def to_hash "disable_date" => disable_date, "disable_reason" => disable_reason, "post_install_defined" => post_install_defined?, - "service" => (service.serialize if service?), + "service" => (service.to_hash if service?), "tap_git_head" => tap_git_head, "ruby_source_path" => ruby_source_path, "ruby_source_checksum" => {}, @@ -2318,7 +2318,7 @@ def to_api_hash 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["caveats"] = caveats_with_placeholders if caveats - api_hash["service"] = service.serialize if service? + api_hash["service"] = service.to_hash if service? if stable api_hash["version"] = stable&.version&.to_s diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 5063333823207..23a214902e0c8 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -341,7 +341,7 @@ def post_install_defined? end if (service_hash = json_formula["service"].presence) - service_hash = Homebrew::Service.deserialize(service_hash) + service_hash = Homebrew::Service.from_hash(service_hash) service do T.bind(self, Homebrew::Service) diff --git a/Library/Homebrew/service.rb b/Library/Homebrew/service.rb index 1fe6e86e6b36b..ae9cf8a9d95e7 100644 --- a/Library/Homebrew/service.rb +++ b/Library/Homebrew/service.rb @@ -515,7 +515,7 @@ def to_systemd_timer # Prepare the service hash for inclusion in the formula API JSON. sig { returns(Hash) } - def serialize + def to_hash name_params = { macos: (plist_name if plist_name != default_plist_name), linux: (service_name if service_name != default_service_name), @@ -568,7 +568,7 @@ def serialize # Turn the service API hash values back into what is expected by the formula DSL. sig { params(api_hash: Hash).returns(Hash) } - def self.deserialize(api_hash) + def self.from_hash(api_hash) hash = {} hash[:name] = api_hash["name"].transform_keys(&:to_sym) if api_hash.key?("name") diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index 94454a9780dfb..414b6004dd738 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -738,7 +738,7 @@ def post_install url "https://brew.sh/test-1.0.tbz" end - expect(f.service.serialize).to eq({}) + expect(f.service.to_hash).to eq({}) end specify "service complicated" do @@ -754,7 +754,7 @@ def post_install keep_alive true 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) end @@ -766,7 +766,7 @@ def post_install 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 specify "service with only custom names" do @@ -779,7 +779,7 @@ def post_install expect(f.plist_name).to eq("custom.macos.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 specify "service helpers return data" do diff --git a/Library/Homebrew/test/service_spec.rb b/Library/Homebrew/test/service_spec.rb index 85f1e8be51476..b5c56fe40b3e2 100644 --- a/Library/Homebrew/test/service_spec.rb +++ b/Library/Homebrew/test/service_spec.rb @@ -1044,7 +1044,7 @@ def stub_formula_with_service_sockets(sockets_var) end end - describe "#serialize" do + describe "#to_hash" do let(:serialized_hash) do { environment_variables: { @@ -1072,12 +1072,12 @@ def stub_formula_with_service_sockets(sockets_var) end Formula.generating_hash! - expect(f.service.serialize).to eq(serialized_hash) + expect(f.service.to_hash).to eq(serialized_hash) Formula.generated_hash! end end - describe ".deserialize" do + describe ".from_hash" do let(:serialized_hash) do { "name" => { @@ -1111,12 +1111,12 @@ def stub_formula_with_service_sockets(sockets_var) end 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 describe "run command" do it "handles String argument correctly" do - expect(described_class.deserialize({ + expect(described_class.from_hash({ "run" => "$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd", })).to eq({ run: "#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd", @@ -1124,7 +1124,7 @@ def stub_formula_with_service_sockets(sockets_var) end it "handles Array argument correctly" do - expect(described_class.deserialize({ + expect(described_class.from_hash({ "run" => ["$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd", "--option"], })).to eq({ run: ["#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd", "--option"], @@ -1132,7 +1132,7 @@ def stub_formula_with_service_sockets(sockets_var) end it "handles Hash argument correctly" do - expect(described_class.deserialize({ + expect(described_class.from_hash({ "run" => { "linux" => "$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd", "macos" => ["$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd", "--option"],