Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Library/Homebrew/services/formula_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,21 @@ def service?
end

# Delegate access to `formula.service.timed?`.
# TODO: this should either be T::Boolean or renamed to `timed`
sig { returns(T.nilable(T::Boolean)) }
sig { returns(T::Boolean) }
def timed?
@timed ||= T.let((load_service.timed? if service?), T.nilable(T::Boolean))
return @timed unless @timed.nil?

@timed = T.let(service? && load_service.timed?, T.nilable(T::Boolean))
T.must(@timed)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@timed = T.let(service? && load_service.timed?, T.nilable(T::Boolean))
T.must(@timed)
@timed = T.let(service? && load_service.timed?, T.nilable(T::Boolean))

don't use T.must here, instead us if or || to ensure the result is always true or false

end

# Delegate access to `formula.service.keep_alive?`.
# TODO: this should either be T::Boolean or renamed to `keep_alive`
sig { returns(T.nilable(T::Boolean)) }
sig { returns(T::Boolean) }
def keep_alive?
@keep_alive ||= T.let((load_service.keep_alive? if service?), T.nilable(T::Boolean))
return @keep_alive unless @keep_alive.nil?

@keep_alive = T.let(service? && load_service.keep_alive?, T.nilable(T::Boolean))
T.must(@keep_alive)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

end

# service_name delegates with formula.plist_name or formula.service_name
Expand Down
12 changes: 6 additions & 6 deletions Library/Homebrew/test/services/formula_wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,10 @@
expect(service.timed?).to be(false)
end

it "returns nil if no service" do
it "returns false if no service" do
allow(service).to receive(:service?).once.and_return(false)

expect(service.timed?).to be_nil
expect(service.timed?).to be(false)
end
end

Expand All @@ -350,10 +350,10 @@
expect(service.keep_alive?).to be(false)
end

it "returns nil if no service" do
it "returns false if no service" do
allow(service).to receive(:service?).once.and_return(false)

expect(service.keep_alive?).to be_nil
expect(service.keep_alive?).to be(false)
end
end

Expand Down Expand Up @@ -383,7 +383,7 @@
pid: nil,
registered: false,
running: false,
schedulable: nil,
schedulable: false,
service_name: "plist-mysql-test",
status: :none,
user: nil,
Expand All @@ -405,7 +405,7 @@
pid: nil,
registered: true,
running: false,
schedulable: nil,
schedulable: false,
service_name: "plist-mysql-test",
status: :none,
user: nil,
Expand Down
Loading