Class: Orchestrator::Core::RequestProxy

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

Instance Method Summary collapse

Constructor Details

#initialize(thread, mod) ⇒ RequestProxy

Returns a new instance of RequestProxy.



48
49
50
51
# File 'lib/orchestrator/core/request_proxy.rb', line 48

def initialize(thread, mod)
    @mod = mod
    @thread = thread
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

All other method calls are wrapped in a promise



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/orchestrator/core/request_proxy.rb', line 81

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
        @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
    end

    defer.promise
end

Instance Method Details

#[](name) ⇒ Object

Simplify access to status variables as they are thread safe



54
55
56
# File 'lib/orchestrator/core/request_proxy.rb', line 54

def [](name)
    @mod.instance[name]
end

#[]=(status, value) ⇒ Object



58
59
60
# File 'lib/orchestrator/core/request_proxy.rb', line 58

def []=(status, value)
    @mod.instance[status] = value
end

#nil?true|false

Returns true if there is no object to proxy

Returns:

  • (true|false)


65
66
67
# File 'lib/orchestrator/core/request_proxy.rb', line 65

def nil?
    @mod.nil?
end

#respond_to?(symbol, include_all = false) ⇒ true|false

Returns true if the module responds to the given method

Returns:

  • (true|false)


72
73
74
75
76
77
78
# File 'lib/orchestrator/core/request_proxy.rb', line 72

def respond_to?(symbol, include_all = false)
    if @mod
        @mod.instance.respond_to?(symbol, include_all)
    else
        false
    end
end