Class: Parallizer::Proxy

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

Instance Method Summary collapse

Constructor Details

#initialize(client, call_infos) ⇒ Proxy

Returns a new instance of Proxy.



5
6
7
8
# File 'lib/parallizer/proxy.rb', line 5

def initialize(client, call_infos)
  @client = client
  @call_infos = call_infos
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/parallizer/proxy.rb', line 10

def method_missing(name, *args, &block)
  if call_info = @call_infos[[name, *args]]
    if call_info[:exception]
      # add the current call stack to the exception backtrace
      exception = call_info[:exception].clone
      exception.set_backtrace((call_info[:exception].backtrace || []) + caller)
      raise exception
    else
      call_info[:result]
    end
  else
    @client.send(*[name, *args], &block)
  end
end

Instance Method Details

#respond_to?(name, include_private = false, &block) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
# File 'lib/parallizer/proxy.rb', line 25

def respond_to?(name, include_private = false, &block)
  @execution_methods ||= Set.new(@call_infos.keys.collect(&:first))

  if @execution_methods.include?(name.to_sym)
    true
  else
    super
  end
end