Skip to content

Commit 196552b

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

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/net/smtp.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,9 @@ def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream
865865
DEFAULT_AUTH_TYPE = :plain
866866

867867
# call-seq:
868+
# authenticate(type: DEFAULT_AUTH_TYPE, **, &)
868869
# authenticate(type = DEFAULT_AUTH_TYPE, **, &)
870+
# authenticate(username, secret, type: DEFAULT_AUTH_TYPE, **, &)
869871
# authenticate(username, secret, type = DEFAULT_AUTH_TYPE, **, &)
870872
#
871873
# Authenticates with the server, using the "AUTH" command.
@@ -882,19 +884,19 @@ def authenticate(*args, **kwargs, &block)
882884
raise ArgumentError, "wrong number of arguments " \
883885
"(given %d, expected 0..3)" % [args.length]
884886
end
885-
authtype ||= DEFAULT_AUTH_TYPE
886-
check_auth_args authtype, *args, **kwargs
887+
authtype, args, kwargs = check_auth_args authtype, *args, **kwargs
887888
authenticator = Authenticator.auth_class(authtype).new(self)
888889
authenticator.auth(*args, **kwargs, &block)
889890
end
890891

891892
private
892893

893-
def check_auth_args(type, *args, **kwargs)
894-
type ||= DEFAULT_AUTH_TYPE
894+
def check_auth_args(type_arg = nil, *args, type: nil, **kwargs)
895+
type ||= type_arg || DEFAULT_AUTH_TYPE
895896
klass = Authenticator.auth_class(type) or
896897
raise ArgumentError, "wrong authentication type #{type}"
897898
klass.check_args(*args, **kwargs)
899+
[type, args, kwargs]
898900
end
899901

900902
#

0 commit comments

Comments
 (0)