Skip to content

Commit 52a3d16

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

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

lib/net/smtp.rb

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

866866
# call-seq:
867+
# authenticate(type: DEFAULT_AUTH_TYPE, **, &)
867868
# authenticate(type = DEFAULT_AUTH_TYPE, **, &)
869+
# authenticate(username, secret, type: DEFAULT_AUTH_TYPE, **, &)
868870
# authenticate(username, secret, type = DEFAULT_AUTH_TYPE, **, &)
869871
#
870872
# Authenticates with the server, using the "AUTH" command.
@@ -881,19 +883,19 @@ def authenticate(*args, **kwargs, &block)
881883
raise ArgumentError, "wrong number of arguments " \
882884
"(given %d, expected 0..3)" % [args.length]
883885
end
884-
authtype ||= DEFAULT_AUTH_TYPE
885-
check_auth_args authtype, *args, **kwargs
886+
authtype, args, kwargs = check_auth_args authtype, *args, **kwargs
886887
authenticator = Authenticator.auth_class(authtype).new(self)
887888
critical { authenticator.auth(*args, **kwargs, &block) }
888889
end
889890

890891
private
891892

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

899901
#

0 commit comments

Comments
 (0)