Skip to content

Commit e0b8f0b

Browse files
committed
♻️ Use Forwardable for SASL:ClientAdapter methods
1 parent 78aebda commit e0b8f0b

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

lib/net/imap/sasl/client_adapter.rb

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require "forwardable"
4+
35
module Net
46
class IMAP
57
module SASL
@@ -23,6 +25,8 @@ module SASL
2325
# possible, ClientAdapter delegates the handling of these requirements to
2426
# SASL::ProtocolAdapters.
2527
class ClientAdapter
28+
extend Forwardable
29+
2630
include ProtocolAdapters::Generic
2731

2832
# The client that handles communication with the protocol server.
@@ -59,11 +63,17 @@ def initialize(client, &command_proc)
5963
# AuthenticationExchange.authenticate.
6064
def authenticate(...) AuthenticationExchange.authenticate(self, ...) end
6165

66+
##
67+
# method: sasl_ir_capable?
6268
# Do the protocol, server, and client all support an initial response?
63-
def sasl_ir_capable?; client.sasl_ir_capable? end
69+
def_delegator :client, :sasl_ir_capable?
6470

71+
##
72+
# method: auth_capable?
73+
# call-seq: auth_capable?(mechanism)
74+
#
6575
# Does the server advertise support for the +mechanism+?
66-
def auth_capable?(mechanism); client.auth_capable?(mechanism) end
76+
def_delegator :client, :auth_capable?
6777

6878
# Calls command_proc with +command_name+ (see
6979
# SASL::ProtocolAdapters::Generic#command_name),
@@ -83,21 +93,29 @@ def run_command(mechanism, initial_response = nil, &continuations_handler)
8393
command_proc.call(*args, &continuations_handler)
8494
end
8595

96+
##
97+
# method: host
8698
# The hostname to which the client connected.
87-
def host; client.host end
99+
def_delegator :client, :host
88100

101+
##
102+
# method: port
89103
# The destination port to which the client connected.
90-
def port; client.port end
104+
def_delegator :client, :port
91105

92106
# Returns an array of server responses errors raised by run_command.
93107
# Exceptions in this array won't drop the connection.
94108
def response_errors; [] end
95109

110+
##
111+
# method: drop_connection
96112
# Drop the connection gracefully, sending a "LOGOUT" command as needed.
97-
def drop_connection; client.drop_connection end
113+
def_delegator :client, :drop_connection
98114

115+
##
116+
# method: drop_connection!
99117
# Drop the connection abruptly, closing the socket without logging out.
100-
def drop_connection!; client.drop_connection! end
118+
def_delegator :client, :drop_connection!
101119

102120
end
103121
end

0 commit comments

Comments
 (0)