Class: Sidekiq::Mailer::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/mailer/proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(mailer, queue = "default") ⇒ Proxy

Returns a new instance of Proxy.



7
8
9
10
# File 'lib/sidekiq/mailer/proxy.rb', line 7

def initialize(mailer, queue = "default")
  @mailer = mailer
  @queue = queue
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/sidekiq/mailer/proxy.rb', line 12

def method_missing(method, *args)
  # assuming that mailer methods take a single AR record may bite us later
  record = args.first
  if @mailer.respond_to?(method)
    Sidekiq::Client.push(@queue, "class" => "Sidekiq::Mailer::Worker",
      "args" => [@mailer.to_s, method, record.class.to_s, record.id])
  else
    raise NoMethodError, "undefined method `#{method}' for #{@mailer}:#{@mailer.class}"
  end
end