Class: Puppeteer::ReactorRunner::Proxy
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Puppeteer::ReactorRunner::Proxy
show all
- Defined in:
- lib/puppeteer/reactor_runner.rb
Instance Method Summary
collapse
Constructor Details
#initialize(runner, target, owns_runner: false) ⇒ Proxy
Returns a new instance of Proxy.
27
28
29
30
31
|
# File 'lib/puppeteer/reactor_runner.rb', line 27
def initialize(runner, target, owns_runner: false)
super(target)
@runner = runner
@owns_runner = owns_runner
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs, &block) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/puppeteer/reactor_runner.rb', line 49
def method_missing(name, *args, **kwargs, &block)
if @runner.closed?
return false if name == :connected?
return nil if @owns_runner && close_like?(name)
end
begin
@runner.sync do
args = args.map { |arg| @runner.unwrap(arg) }
kwargs = kwargs.transform_values { |value| @runner.unwrap(value) }
result = __getobj__.public_send(name, *args, **kwargs, &block)
@runner.wrap(result)
end
ensure
if @owns_runner && close_like?(name)
@runner.wait_until_idle
@runner.close
end
end
end
|
Instance Method Details
#==(other) ⇒ Object
92
93
94
|
# File 'lib/puppeteer/reactor_runner.rb', line 92
def ==(other)
__getobj__ == @runner.unwrap(other)
end
|
#class ⇒ Object
74
75
76
|
# File 'lib/puppeteer/reactor_runner.rb', line 74
def class
__getobj__.class
end
|
#eql?(other) ⇒ Boolean
96
97
98
|
# File 'lib/puppeteer/reactor_runner.rb', line 96
def eql?(other)
__getobj__.eql?(@runner.unwrap(other))
end
|
#hash ⇒ Object
100
101
102
|
# File 'lib/puppeteer/reactor_runner.rb', line 100
def hash
__getobj__.hash
end
|
#instance_of?(klass) ⇒ Boolean
86
87
88
89
90
|
# File 'lib/puppeteer/reactor_runner.rb', line 86
def instance_of?(klass)
return true if klass == Proxy || klass == self.class
__getobj__.instance_of?(klass)
end
|
#is_a?(klass) ⇒ Boolean
Also known as:
kind_of?
78
79
80
81
82
|
# File 'lib/puppeteer/reactor_runner.rb', line 78
def is_a?(klass)
return true if klass == Proxy || klass == self.class
__getobj__.is_a?(klass)
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
70
71
72
|
# File 'lib/puppeteer/reactor_runner.rb', line 70
def respond_to_missing?(name, include_private = false)
__getobj__.respond_to?(name, include_private) || super
end
|
#tap(*args, **kwargs, &block) ⇒ Object
Override tap to distinguish between Ruby’s Object#tap and Puppeteer’s tap method. When called with a block only (Ruby’s tap), delegate to super. When called with args (Puppeteer’s tap), route through the reactor.
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/puppeteer/reactor_runner.rb', line 36
def tap(*args, **kwargs, &block)
if args.empty? && kwargs.empty? && block
super(&block)
else
@runner.sync do
args = args.map { |arg| @runner.unwrap(arg) }
kwargs = kwargs.transform_values { |value| @runner.unwrap(value) }
result = __getobj__.public_send(:tap, *args, **kwargs, &block)
@runner.wrap(result)
end
end
end
|