Class: QC::Mailer::MessageDecoy

Inherits:
Object
  • Object
show all
Defined in:
lib/qc-mailer/message_decoy.rb

Instance Method Summary collapse

Constructor Details

#initialize(mailer_class, method_name, *args) ⇒ MessageDecoy

Returns a new instance of MessageDecoy.



9
10
11
12
13
# File 'lib/qc-mailer/message_decoy.rb', line 9

def initialize(mailer_class, method_name, *args)
  @mailer_class   = mailer_class
  @method_name    = method_name.to_s
  *@args          = *args
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



27
28
29
# File 'lib/qc-mailer/message_decoy.rb', line 27

def method_missing(method_name, *args)
  actual_message.send(method_name, *args)
end

Instance Method Details

#actual_messageObject



15
16
17
# File 'lib/qc-mailer/message_decoy.rb', line 15

def actual_message
  @actual_message ||= @mailer_class.send(:new, @method_name, *@args).message
end

#deliverObject



19
20
21
# File 'lib/qc-mailer/message_decoy.rb', line 19

def deliver
  @mailer_class.queue.enqueue("#{@mailer_class}.deliver", @method_name, *@args)
end

#deliver!Object



23
24
25
# File 'lib/qc-mailer/message_decoy.rb', line 23

def deliver!
  actual_message.deliver
end