class Quebert::AsyncSender::Promise

Decorates AsyncSender classes with an async() proxy. This seperates the concern of configuring job specific parameters, like :ttr, :delay, etc. from calling the method.

Attributes

job[R]
opts[R]
target[R]

Public Class Methods

new(target, opts={}, &block) click to toggle source
# File lib/quebert/async_sender/promise.rb, line 9
def initialize(target, opts={}, &block)
  @target, @opts, @block = target, opts, block
  self
end

Public Instance Methods

configure(job) click to toggle source

Configures a job with the options provied to the Promise upon initialization.

# File lib/quebert/async_sender/promise.rb, line 28
def configure(job)
  @opts.each do |attr, val|
    job.send("#{attr}=", val)
  end
  job
end
method_missing(meth, *args) click to toggle source

Proxies the method call from async to the target, then tries to build a job with the targets `build_job` function.

Calls superclass method
# 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