Skip to content
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

Public disconnect methods #86

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

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 5 times, most recently from 4ce9c44 to ec73e62 Compare May 8, 2024 19:27
nevans added 2 commits May 8, 2024 15:35
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 ec73e62 to f79bbb5 Compare May 8, 2024 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant