Skip to content

Commit

Permalink
Add type keyword arg to #authenticate
Browse files Browse the repository at this point in the history
This is convenient for `smtp.start auth: {type:, **etc}`.
  • Loading branch information
nevans committed Oct 15, 2023
1 parent e4e64e5 commit 52a3d16
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/net/smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,9 @@ def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream
DEFAULT_AUTH_TYPE = :plain

# call-seq:
# authenticate(type: DEFAULT_AUTH_TYPE, **, &)
# authenticate(type = DEFAULT_AUTH_TYPE, **, &)
# authenticate(username, secret, type: DEFAULT_AUTH_TYPE, **, &)
# authenticate(username, secret, type = DEFAULT_AUTH_TYPE, **, &)
#
# Authenticates with the server, using the "AUTH" command.
Expand All @@ -881,19 +883,19 @@ def authenticate(*args, **kwargs, &block)
raise ArgumentError, "wrong number of arguments " \
"(given %d, expected 0..3)" % [args.length]
end
authtype ||= DEFAULT_AUTH_TYPE
check_auth_args authtype, *args, **kwargs
authtype, args, kwargs = check_auth_args authtype, *args, **kwargs
authenticator = Authenticator.auth_class(authtype).new(self)
critical { authenticator.auth(*args, **kwargs, &block) }
end

private

def check_auth_args(type, *args, **kwargs)
type ||= DEFAULT_AUTH_TYPE
def check_auth_args(type_arg = nil, *args, type: nil, **kwargs)
type ||= type_arg || DEFAULT_AUTH_TYPE
klass = Authenticator.auth_class(type) or
raise ArgumentError, "wrong authentication type #{type}"
klass.check_args(*args, **kwargs)
[type, args, kwargs]
end

#
Expand Down

0 comments on commit 52a3d16

Please sign in to comment.