class Orchestrator::Core::RequestProxy

Attributes

trace[R]

Public Class Methods

new(thread, mod, user = nil) click to toggle source
# File lib/orchestrator/core/request_proxy.rb, line 48
def initialize(thread, mod, user = nil)
    @mod = mod
    @thread = thread
    @user = user
    @trace = []
end

Public Instance Methods

[](name) click to toggle source

Simplify access to status variables as they are thread safe

# File lib/orchestrator/core/request_proxy.rb, line 60
def [](name)
    @mod.instance[name]
end
[]=(status, value) click to toggle source
# File lib/orchestrator/core/request_proxy.rb, line 64
def []=(status, value)
    @mod.instance[status] = value
end
arity(method) click to toggle source

Looks up the arity of a method

# File lib/orchestrator/core/request_proxy.rb, line 87
def arity(method)
    @mod.instance.method(method.to_sym).arity
end
method_missing(name, *args, &block) click to toggle source

All other method calls are wrapped in a promise

# File lib/orchestrator/core/request_proxy.rb, line 92
def method_missing(name, *args, &block)
    defer = @thread.defer

    if @mod.nil?
        err = Error::ModuleUnavailable.new "method '#{name}' request failed as the module is not available at this time"
        defer.reject(err)
        # TODO:: debug log here
    elsif ::Orchestrator::Core::PROTECTED[name]
        err = Error::ProtectedMethod.new "attempt to access module '#{@mod.settings.id}' protected method '#{name}'"
        defer.reject(err)
        @mod.logger.warn(err.message)
    else
        @trace = caller

        @mod.thread.schedule do
            # Keep track of previous in case of recursion
            previous = nil
            begin
                if @user
                    previous = @mod.current_user
                    @mod.current_user = @user
                end
                
                defer.resolve(
                    @mod.instance.public_send(name, *args, &block)
                )
            rescue => e
                @mod.logger.print_error(e, '', @trace)
                defer.reject(e)
            ensure
                @mod.current_user = previous if @user
            end
        end
    end

    defer.promise
end
nil?() click to toggle source

Returns true if there is no object to proxy

@return [true|false]

# File lib/orchestrator/core/request_proxy.rb, line 71
def nil?
    @mod.nil?
end
respond_to?(symbol, include_all = false) click to toggle source

Returns true if the module responds to the given method

@return [true|false]

# File lib/orchestrator/core/request_proxy.rb, line 78
def respond_to?(symbol, include_all = false)
    if @mod
        @mod.instance.respond_to?(symbol, include_all)
    else
        false
    end
end