Skip to content

Conversation

nevans
Copy link
Contributor

@nevans nevans commented May 8, 2024

There are circumstances when an authenticator needs to disconnect the client before @start = true. This PR refactors the private #do_finish method:

  • renames it to #quit!,
  • makes it public,
  • adds an option to ignore or warn on exceptions,
  • extracts its ensure block into a new public #disconnect method.

The motivation for making these public is given in the rdoc.

As documented in the rdoc, #quit!:

Calls #quit and ensures that #disconnect is called. Returns the
result from #quit. Returns +nil+ when the client is already
disconnected or when a prior error prevents the client from calling
#quit. Unlike #finish, this an exception will not be raised when the
client has not started.

If #quit raises a StandardError, the connection is dropped and the
exception is re-raised. When exception: :warn is specified,
a warning is printed and the exception is returned. When
exception: false is specified, the warning is not printed.
This is useful when the connection must be dropped, for example in a
test suite or due to security concerns.

As documented in the rdoc, #disconnect:

Disconnects the socket without checking if the connection has started
yet, and without sending a final QUIT message to the server.

Generally, either #finish or #quit! should be used instead.

@nevans nevans force-pushed the public-disconnect-methods branch 6 times, most recently from ec73e62 to f79bbb5 Compare May 8, 2024 19:35
nevans added 2 commits July 17, 2025 13:50
This renames `#do_finish` to `#quit!`, makes it public, adds an option
to convert exceptions into warnings, and extracts the contents of the
ensure block into a new public `#disconnect` method.  The motivation for
making these public is given in the rdoc.

As documented in the rdoc, `#quit!`:
> Calls #quit and ensures that #disconnect is called.  Returns the
> result from #quit.  Returns +nil+ when the client is already
> disconnected or when a prior error prevents the client from calling
> #quit.  Unlike #finish, this an exception will not be raised when the
> client has not started.
>
> If #quit raises a StandardError, the connection is dropped and the
> exception is re-raised.  When <tt>exception: :warn</tt> is specified,
> a warning is printed and the exception is returned.  When
> <tt>exception: false</tt> is specified, the warning is not printed.
> This is useful when the connection must be dropped, for example in a
> test suite or due to security concerns.

As documented in the rdoc, `#disconnect`:
> Disconnects the socket without checking if the connection has started
> yet, and without sending a final QUIT message to the server.
>
> Generally, either #finish or #quit! should be used instead.

fix docs

fix doc
@nevans nevans force-pushed the public-disconnect-methods branch from f79bbb5 to 1db3a9e Compare July 17, 2025 17:51
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.

1 participant