Skip to content

Commit a6280b6

Browse files
committed
Add type keyword arg to #authenticate
This is convenient for `smtp.start auth: {type:, **etc}`.
1 parent 6be96ea commit a6280b6

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/net/smtp.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -879,12 +879,14 @@ def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream
879879
DEFAULT_AUTH_TYPE = :plain
880880

881881
# call-seq:
882-
# authenticate(authtype = DEFAULT_AUTH_TYPE, **, &)
883-
# authenticate(username, secret, authtype = DEFAULT_AUTH_TYPE, **, &)
882+
# authenticate(type: DEFAULT_AUTH_TYPE, **, &)
883+
# authenticate(type = DEFAULT_AUTH_TYPE, **, &)
884+
# authenticate(username, secret, type: DEFAULT_AUTH_TYPE, **, &)
885+
# authenticate(username, secret, type = DEFAULT_AUTH_TYPE, **, &)
884886
#
885887
# Authenticates with the server, using the "AUTH" command.
886888
#
887-
# +authtype+ is the name of a SASL authentication mechanism.
889+
# +type+ is the name of a SASL authentication mechanism.
888890
#
889891
# All arguments—other than +authtype+—are forwarded to the authenticator.
890892
# Different authenticators may interpret the +username+ and +secret+
@@ -896,19 +898,19 @@ def authenticate(*args, **kwargs, &block)
896898
raise ArgumentError, "wrong number of arguments " \
897899
"(given %d, expected 0..3)" % [args.length]
898900
end
899-
authtype ||= DEFAULT_AUTH_TYPE
900-
check_auth_args authtype, *args, **kwargs
901+
authtype, args, kwargs = check_auth_args authtype, *args, **kwargs
901902
authenticator = Authenticator.auth_class(authtype).new(self)
902903
authenticator.auth(*args, **kwargs, &block)
903904
end
904905

905906
private
906907

907-
def check_auth_args(type, *args, **kwargs)
908-
type ||= DEFAULT_AUTH_TYPE
908+
def check_auth_args(type_arg = nil, *args, type: nil, **kwargs)
909+
type ||= type_arg || DEFAULT_AUTH_TYPE
909910
klass = Authenticator.auth_class(type) or
910911
raise ArgumentError, "wrong authentication type #{type}"
911912
klass.check_args(*args, **kwargs)
913+
[type, args, kwargs]
912914
end
913915

914916
#

0 commit comments

Comments
 (0)