Class: Rage::Deferred::Proxy
- Inherits:
-
Object
- Object
- Rage::Deferred::Proxy
- Defined in:
- lib/rage/deferred/proxy.rb
Defined Under Namespace
Classes: Wrapper
Instance Method Summary collapse
-
#initialize(instance, delay: nil, delay_until: nil) ⇒ Proxy
constructor
A new instance of Proxy.
- #method_missing(method_name) ⇒ Object
- #respond_to_missing?(method_name, _) ⇒ Boolean
Constructor Details
#initialize(instance, delay: nil, delay_until: nil) ⇒ Proxy
Returns a new instance of Proxy.
12 13 14 15 16 17 |
# File 'lib/rage/deferred/proxy.rb', line 12 def initialize(instance, delay: nil, delay_until: nil) @instance = instance @delay = delay @delay_until = delay_until end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rage/deferred/proxy.rb', line 19 def method_missing(method_name, *, **) if @instance.respond_to?(method_name) self.class.define_method(method_name) do |*args, **kwargs| Wrapper.enqueue(@instance, method_name, *args, delay: @delay, delay_until: @delay_until, **kwargs) end send(method_name, *, **) else @instance.public_send(method_name, *, **) end end |
Instance Method Details
#respond_to_missing?(method_name, _) ⇒ Boolean
31 32 33 |
# File 'lib/rage/deferred/proxy.rb', line 31 def respond_to_missing?(method_name, _) @instance.respond_to?(method_name) end |