Skip to content

Commit d715277

Browse files
committed
Do not require positional args for #authenticate
This API is a little bit confusing, IMO. But it does preserve backward compatibility, while allowing authenticators that don't allow positional parameters to work without crashing. But, authenticators that require only one parameter—or more than three—will still be inaccessible.
1 parent 1a81492 commit d715277

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

lib/net/smtp.rb

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -864,17 +864,28 @@ def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream
864864

865865
DEFAULT_AUTH_TYPE = :plain
866866

867+
# call-seq:
868+
# authenticate(type = DEFAULT_AUTH_TYPE, **, &)
869+
# authenticate(username, secret, type = DEFAULT_AUTH_TYPE, **, &)
870+
#
867871
# Authenticates with the server, using the "AUTH" command.
868872
#
869-
# +authtype+ is the name of a SASL authentication mechanism.
873+
# +type+ is the name of a SASL authentication mechanism.
870874
#
871-
# All arguments—other than +authtype+—are forwarded to the authenticator.
872-
# Different authenticators may interpret the +user+ and +secret+
875+
# All arguments—other than +type+—are forwarded to the authenticator.
876+
# Different authenticators may interpret the +username+ and +secret+
873877
# arguments differently.
874-
def authenticate(user, secret, authtype = DEFAULT_AUTH_TYPE, **kwargs, &block)
875-
check_auth_args authtype, user, secret, **kwargs
878+
def authenticate(*args, **kwargs, &block)
879+
case args.length
880+
when 1, 3 then authtype = args.pop
881+
when (4..)
882+
raise ArgumentError, "wrong number of arguments " \
883+
"(given %d, expected 0..3)" % [args.length]
884+
end
885+
authtype ||= DEFAULT_AUTH_TYPE
886+
check_auth_args authtype, *args, **kwargs
876887
authenticator = Authenticator.auth_class(authtype).new(self)
877-
authenticator.auth(user, secret, **kwargs, &block)
888+
authenticator.auth(*args, **kwargs, &block)
878889
end
879890

880891
private

0 commit comments

Comments
 (0)