lib/net/imap/sasl/authenticators.rb in net-imap-0.4.0 vs lib/net/imap/sasl/authenticators.rb in net-imap-0.4.1
- old
+ new
@@ -63,11 +63,11 @@
#
# When only a single argument is given, the authenticator class will be
# lazily loaded from <tt>Net::IMAP::SASL::#{name}Authenticator</tt> (case is
# preserved and non-alphanumeric characters are removed..
def add_authenticator(name, authenticator = nil)
- key = name.upcase.to_sym
+ key = -name.to_s.upcase.tr(?_, ?-)
authenticator ||= begin
class_name = "#{name.gsub(/[^a-zA-Z0-9]/, "")}Authenticator".to_sym
auth_class = nil
->(*creds, **props, &block) {
auth_class ||= Net::IMAP::SASL.const_get(class_name)
@@ -77,14 +77,19 @@
@authenticators[key] = authenticator
end
# Removes the authenticator registered for +name+
def remove_authenticator(name)
- key = name.upcase.to_sym
+ key = -name.to_s.upcase.tr(?_, ?-)
@authenticators.delete(key)
end
+ def mechanism?(name)
+ key = -name.to_s.upcase.tr(?_, ?-)
+ @authenticators.key?(key)
+ end
+
# :call-seq:
# authenticator(mechanism, ...) -> auth_session
#
# Builds an authenticator instance using the authenticator registered to
# +mechanism+. The returned object represents a single authentication
@@ -98,11 +103,12 @@
# [Note]
# This method is intended for internal use by connection protocol code
# only. Protocol client users should see refer to their client's
# documentation, e.g. Net::IMAP#authenticate.
def authenticator(mechanism, ...)
- auth = @authenticators.fetch(mechanism.upcase.to_sym) do
- raise ArgumentError, 'unknown auth type - "%s"' % mechanism
+ key = -mechanism.to_s.upcase.tr(?_, ?-)
+ auth = @authenticators.fetch(key) do
+ raise ArgumentError, 'unknown auth type - "%s"' % key
end
auth.respond_to?(:new) ? auth.new(...) : auth.call(...)
end
alias new authenticator