Class: Orchestrator::Core::RequestsProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/orchestrator/core/requests_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(thread, modules) ⇒ RequestsProxy

Returns a new instance of RequestsProxy.



4
5
6
7
8
9
10
11
# File 'lib/orchestrator/core/requests_proxy.rb', line 4

def initialize(thread, modules)
    if modules.nil?
        @modules = []
    else
        @modules = modules.is_a?(Array) ? modules : [modules]
    end
    @thread = thread
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/orchestrator/core/requests_proxy.rb', line 21

def method_missing(name, *args, &block)
    if ::Orchestrator::Core::PROTECTED[name]
        err = Error::ProtectedMethod.new "attempt to access a protected method '#{name}' in multiple modules"
        ::Libuv::Q.reject(@thread, err)
        # TODO:: log warning err.message
    else
        promises = @modules.map do |mod|
            defer = mod.thread.defer
            mod.thread.schedule do
                begin
                    defer.resolve(
                        mod.instance.public_send(name, *args, &block)
                    )
                rescue => e
                    mod.logger.print_error(e)
                    defer.reject(e)
                end
            end
            defer.promise
        end

        @thread.finally(*promises)
    end
end

Instance Method Details

#nil?true|false Also known as: empty?

Returns true if there is no object to proxy

Returns:

  • (true|false)


16
17
18
# File 'lib/orchestrator/core/requests_proxy.rb', line 16

def nil?
    @modules.empty?
end