Class: Orchestrator::Core::RequestsProxy
- Inherits:
-
Object
- Object
- Orchestrator::Core::RequestsProxy
- Extended by:
- Forwardable
- Defined in:
- lib/orchestrator/core/requests_proxy.rb
Instance Attribute Summary collapse
-
#trace ⇒ Object
readonly
Returns the value of attribute trace.
Instance Method Summary collapse
- #[](index) ⇒ Object (also: #at)
-
#each ⇒ Object
Provide Enumerable support.
- #first ⇒ Object
-
#initialize(thread, modules, user = nil) ⇒ RequestsProxy
constructor
A new instance of RequestsProxy.
- #last ⇒ Object
- #method_missing(name, *args, &block) ⇒ Object
-
#nil? ⇒ true|false
Returns true if there is no object to proxy Allows RequestProxy and RequestsProxy to be used interchangably.
Constructor Details
#initialize(thread, modules, user = nil) ⇒ RequestsProxy
Returns a new instance of RequestsProxy.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/orchestrator/core/requests_proxy.rb', line 9 def initialize(thread, modules, user = nil) if modules.nil? @modules = [] else @modules = modules.is_a?(Array) ? modules : [modules] end @thread = thread @user = user @trace = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/orchestrator/core/requests_proxy.rb', line 64 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 @trace = caller promises = @modules.map do |mod| defer = mod.thread.defer 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 defer.promise end @thread.finally(*promises) end end |
Instance Attribute Details
#trace ⇒ Object (readonly)
Returns the value of attribute trace.
21 22 23 |
# File 'lib/orchestrator/core/requests_proxy.rb', line 21 def trace @trace end |
Instance Method Details
#[](index) ⇒ Object Also known as: at
48 49 50 51 52 |
# File 'lib/orchestrator/core/requests_proxy.rb', line 48 def [](index) mod = @modules[index] return nil unless mod return RequestProxy.new(@thread, mod, @user) end |
#each ⇒ Object
Provide Enumerable support
25 26 27 28 29 30 31 |
# File 'lib/orchestrator/core/requests_proxy.rb', line 25 def each return enum_for(:each) unless block_given? @modules.each do |mod| yield RequestProxy.new(@thread, mod, @user) end end |
#first ⇒ Object
42 43 44 45 46 |
# File 'lib/orchestrator/core/requests_proxy.rb', line 42 def first mod = @modules.first return nil unless mod return RequestProxy.new(@thread, mod, @user) end |
#last ⇒ Object
36 37 38 39 40 |
# File 'lib/orchestrator/core/requests_proxy.rb', line 36 def last mod = @modules.last return nil unless mod return RequestProxy.new(@thread, mod, @user) end |
#nil? ⇒ true|false
Returns true if there is no object to proxy Allows RequestProxy and RequestsProxy to be used interchangably
59 60 61 |
# File 'lib/orchestrator/core/requests_proxy.rb', line 59 def nil? @modules.empty? end |