Class: Imap::Backup::Client::AutomaticLoginWrapper

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from RetryOnError

#retry_on_error

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, *arguments, &block) ⇒ Object

Proxies calls to the client. Before the first call does login

Returns:

  • the return value of the client method called



26
27
28
29
30
31
32
33
# File 'lib/imap/backup/client/automatic_login_wrapper.rb', line 26

def method_missing(method_name, *arguments, &block)
  if 
    client.send(method_name, *arguments, &block)
  else
    
    client.send(method_name, *arguments, &block) if method_name != :login
  end
end

Instance Attribute Details

#clientClient (readonly)

Returns:



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.

Returns:

  • (Boolean)

    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