Normalize service serialization method names
This commit is contained in:
parent
d9a98ac4ec
commit
3c503cdf56
@ -2255,7 +2255,7 @@ class Formula
|
||||
"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 @@ 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["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
|
||||
|
@ -341,7 +341,7 @@ module Formulary
|
||||
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)
|
||||
|
||||
|
@ -515,7 +515,7 @@ module Homebrew
|
||||
|
||||
# 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 @@ module Homebrew
|
||||
|
||||
# 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")
|
||||
|
||||
|
@ -738,7 +738,7 @@ describe Formula do
|
||||
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 @@ describe Formula do
|
||||
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 @@ describe Formula do
|
||||
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 @@ describe Formula do
|
||||
|
||||
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
|
||||
|
@ -1044,7 +1044,7 @@ describe Homebrew::Service do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#serialize" do
|
||||
describe "#to_hash" do
|
||||
let(:serialized_hash) do
|
||||
{
|
||||
environment_variables: {
|
||||
@ -1072,12 +1072,12 @@ describe Homebrew::Service do
|
||||
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 @@ describe Homebrew::Service do
|
||||
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 @@ describe Homebrew::Service do
|
||||
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 @@ describe Homebrew::Service do
|
||||
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"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user