Class: Quebert::AsyncSender::Promise
- Inherits:
-
Object
- Object
- Quebert::AsyncSender::Promise
- Defined in:
- lib/quebert/async_sender/promise.rb
Overview
Decorates AsyncSender classes with an #async() proxy. This seperates the concern of configuring job specific parameters, like :ttr, :delay, etc. from calling the method.
Defined Under Namespace
Modules: DSL
Instance Attribute Summary collapse
-
#job ⇒ Object
readonly
Returns the value of attribute job.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#configure(job) ⇒ Object
Configures a job with the options provied to the Promise upon initialization.
-
#initialize(target, opts = {}, &block) ⇒ Promise
constructor
A new instance of Promise.
-
#method_missing(meth, *args) ⇒ Object
Proxies the method call from async to the target, then tries to build a job with the targets ‘build_job` function.
Constructor Details
#initialize(target, opts = {}, &block) ⇒ Promise
Returns a new instance of Promise.
9 10 11 12 |
# File 'lib/quebert/async_sender/promise.rb', line 9 def initialize(target, opts={}, &block) @target, @opts, @block = target, opts, block self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
Proxies the method call from async to the target, then tries to build a job with the targets ‘build_job` function.
16 17 18 19 20 21 22 23 24 |
# File 'lib/quebert/async_sender/promise.rb', line 16 def method_missing(meth, *args) if @target.respond_to? meth, true # The second `true` argument checks private methods. # Create an instance of the job through the proxy and # configure it with the options given to the proxy. @block.call configure @target.build_job(meth, *args) else super end end |
Instance Attribute Details
#job ⇒ Object (readonly)
Returns the value of attribute job.
7 8 9 |
# File 'lib/quebert/async_sender/promise.rb', line 7 def job @job end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
7 8 9 |
# File 'lib/quebert/async_sender/promise.rb', line 7 def opts @opts end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
7 8 9 |
# File 'lib/quebert/async_sender/promise.rb', line 7 def target @target end |
Instance Method Details
#configure(job) ⇒ Object
Configures a job with the options provied to the Promise upon initialization.
28 29 30 31 32 33 |
# File 'lib/quebert/async_sender/promise.rb', line 28 def configure(job) @opts.each do |attr, val| job.send("#{attr}=", val) end job end |