Class: Imap::Backup::Client::AutomaticLoginWrapper
- Inherits:
-
Object
- Object
- Imap::Backup::Client::AutomaticLoginWrapper
- Includes:
- RetryOnError
- Defined in:
- lib/imap/backup/client/automatic_login_wrapper.rb
Overview
Transparently wraps a client instance, while delaying login until it becomes necessary
Constant Summary collapse
- LOGIN_RETRY_CLASSES =
[::EOFError, ::Errno::ECONNRESET, ::SocketError].freeze
Instance Attribute Summary collapse
- #client ⇒ Client readonly
Instance Method Summary collapse
-
#initialize(client:) ⇒ AutomaticLoginWrapper
constructor
A new instance of AutomaticLoginWrapper.
-
#method_missing(method_name) ⇒ Object
Proxies calls to the client.
-
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
Whether the client responds to the method.
Methods included from RetryOnError
Constructor Details
#initialize(client:) ⇒ AutomaticLoginWrapper
Returns a new instance of AutomaticLoginWrapper.
18 19 20 21 |
# File 'lib/imap/backup/client/automatic_login_wrapper.rb', line 18 def initialize(client:) @client = client @login_called = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
Proxies calls to the client. Before the first call does login
26 27 28 29 30 31 32 33 |
# File 'lib/imap/backup/client/automatic_login_wrapper.rb', line 26 def method_missing(method_name, ...) if login_called client.send(method_name, ...) else do_first_login client.send(method_name, ...) if method_name != :login end end |
Instance Attribute Details
#client ⇒ Client (readonly)
16 17 18 |
# File 'lib/imap/backup/client/automatic_login_wrapper.rb', line 16 def client @client end |
Instance Method Details
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
Returns whether the client responds to the method.
36 37 38 |
# File 'lib/imap/backup/client/automatic_login_wrapper.rb', line 36 def respond_to_missing?(method_name, _include_private = false) client.respond_to?(method_name) end |