Class: Reactor::Workers::MailerWorker

Inherits:
Object
  • Object
show all
Includes:
Configuration
Defined in:
lib/reactor/workers/mailer_worker.rb

Constant Summary

Constants included from Configuration

Configuration::CONFIG

Instance Method Summary collapse

Methods included from Configuration

#configured?, #should_perform?

Instance Method Details

#deliver(msg) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/reactor/workers/mailer_worker.rb', line 25

def deliver(msg)
  if msg.respond_to?(:deliver_now)
    # Rails 4.2/5.0
    msg.deliver_now
  else
    # Rails 3.2/4.0/4.1 + Generic Mail::Message
    msg.deliver
  end
end

#deliverable?(msg) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/reactor/workers/mailer_worker.rb', line 35

def deliverable?(msg)
  msg.respond_to?(:deliver_now) || msg.respond_to?(:deliver)
end

#perform(data) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/reactor/workers/mailer_worker.rb', line 11

def perform(data)
  raise_unconfigured! unless configured?
  return :__perform_aborted__ unless should_perform?
  event = Reactor::Event.new(data)

  msg = if action.is_a?(Symbol)
    source.send(action, event)
  else
    source.class_exec event, &action
  end

  deliverable?(msg) ? deliver(msg) : msg
end