Skip to content

Commit

Permalink
Merge pull request #12988 from apainintheneck/add_keep_alive
Browse files Browse the repository at this point in the history
Added Service#keep_alive? method
  • Loading branch information
Bo98 committed Mar 14, 2022
2 parents f0f1eb6 + 62de156 commit fbc5b11
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Library/Homebrew/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ def keep_alive(value = nil)
end
end

# Returns a `Boolean` describing if a service is set to be kept alive.
# @return [Boolean]
sig { returns(T::Boolean) }
def keep_alive?
instance_eval(&@service_block)
@keep_alive == true
end

sig { params(value: T.nilable(T::Boolean)).returns(T.nilable(T::Boolean)) }
def launch_only_once(value = nil)
case T.unsafe(value)
Expand Down
28 changes: 28 additions & 0 deletions Library/Homebrew/test/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,34 @@
end
end

describe "#keep_alive?" do
it "returns true when keep_alive set to true" do
f.class.service do
run [opt_bin/"beanstalkd", "test"]
keep_alive true
end

expect(f.service.keep_alive?).to be(true)
end

it "returns false when keep_alive not set" do
f.class.service do
run [opt_bin/"beanstalkd", "test"]
end

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

it "returns false when keep_alive set to false" do
f.class.service do
run [opt_bin/"beanstalkd", "test"]
keep_alive false
end

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

describe "#command" do
it "returns @run data" do
f.class.service do
Expand Down

0 comments on commit fbc5b11

Please sign in to comment.