Skip to content

Simplify Service attr helper methods #20391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

dduugg
Copy link
Member

@dduugg dduugg commented Aug 6, 2025

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Following through on the discussion at #20324 (comment)

when String, Pathname
@working_dir = path.to_s
end
path ? @working_dir = path.to_s : @working_dir
Copy link
Member

Choose a reason for hiding this comment

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

I feel like an if/else would read a bit nicer here given the logic is mildly more complex than typical for a ternary.

Copy link
Member Author

Choose a reason for hiding this comment

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

done! PTAL.

@dduugg dduugg force-pushed the dug/service-refactor branch from 319b39c to 6c18f5c Compare August 6, 2025 18:04
@@ -178,10 +173,9 @@ def keep_alive(value = nil)

sig { params(value: T.nilable(T::Boolean)).returns(T::Boolean) }
def require_root(value = nil)
case value
when nil
if value.nil?
Copy link
Member Author

Choose a reason for hiding this comment

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

For boolean barams, we have to explicitly check .nil?, which inverts the logic. I could use this same approach for non-boolean param methods for consistency, if desirable.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine like this, thanks!

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Looks good! Fine to merge as-is and continue discussing either in this PR or a follow-up.

@@ -178,10 +173,9 @@ def keep_alive(value = nil)

sig { params(value: T.nilable(T::Boolean)).returns(T::Boolean) }
def require_root(value = nil)
case value
when nil
if value.nil?
Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine like this, thanks!

Comment on lines 110 to 111
sig { params(path: T.nilable(T.any(String, Pathname))).returns(T.nilable(String)) }
def working_dir(path = nil)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
sig { params(path: T.nilable(T.any(String, Pathname))).returns(T.nilable(String)) }
def working_dir(path = nil)
sig { params(path: T.any(String, Pathname)).returns(T.nilable(String)) }
def working_dir(path = T.unsafe(nil))

@dduugg thoughts on this form?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm fine with it, if you don't mind narrowing the existing contract. Lemme update the code, and we can see what breaks 😬

@dduugg dduugg force-pushed the dug/service-refactor branch from 3df90b6 to 02b6abc Compare August 10, 2025 16:32
@@ -23,7 +23,7 @@ class Service
PROCESS_TYPE_ADAPTIVE = :adaptive

KEEP_ALIVE_KEYS = [:always, :successful_exit, :crashed, :path].freeze
SOCKET_STRING_REGEX = %r{^([a-z]+)://(.+):([0-9]+)$}i
SOCKET_STRING_REGEX = %r{^(?<type>[a-z]+)://(?<host>.+):(?<port>[0-9]+)$}i
Copy link
Member Author

Choose a reason for hiding this comment

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

cc @carlocab 😎

(following through on #20324 (comment) )

@dduugg dduugg force-pushed the dug/service-refactor branch from 02b6abc to 899a6c5 Compare August 10, 2025 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants