Class: RetriableProxy::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/retriable_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(with_object, options_for_retriable = {}) ⇒ Wrapper

Creates a new Wrapper that will wrap the messages to the wrapped object with a retriable block.

If the :methods option is passed, only the methods in the given array will be subjected to retries.



12
13
14
15
16
# File 'lib/retriable_proxy.rb', line 12

def initialize(with_object, options_for_retriable = {})
  @o = with_object
  @methods = options_for_retriable.delete(:methods)
  @retriable_options = options_for_retriable
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*a) ⇒ Object

Forwards all methods not defined on the Wrapper to the wrapped object.



29
30
31
32
33
34
35
36
# File 'lib/retriable_proxy.rb', line 29

def method_missing(*a)
  method_name = a[0]
  if block_given?
    __retrying(method_name) { @o.public_send(*a){|*ba| yield(*ba)} }
  else
    __retrying(method_name) { @o.public_send(*a) }
  end
end

Instance Method Details

#__getobj__Object

Returns the wrapped object



19
20
21
# File 'lib/retriable_proxy.rb', line 19

def __getobj__
  @o
end

#respond_to_missing?(*a) ⇒ Boolean

Assists in supporting method_missing

Returns:

  • (Boolean)


24
25
26
# File 'lib/retriable_proxy.rb', line 24

def respond_to_missing?(*a)
  @o.respond_to?(*a)
end