Class: Que::Mailer::MessageDecoy

Inherits:
Object
  • Object
show all
Defined in:
lib/que_mailer.rb

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of MessageDecoy.



60
61
62
63
64
65
# File 'lib/que_mailer.rb', line 60

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



99
100
101
# File 'lib/que_mailer.rb', line 99

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

Instance Method Details

#actual_messageObject



75
76
77
# File 'lib/que_mailer.rb', line 75

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

#current_envObject



67
68
69
70
71
72
73
# File 'lib/que_mailer.rb', line 67

def current_env
  if defined?(Rails)
    ::Que::Mailer.current_env || ::Rails.env
  else
    ::Que::Mailer.current_env
  end
end

#deliverObject



79
80
81
82
83
# File 'lib/que_mailer.rb', line 79

def deliver
  if @mailer_class.deliver?
    MailJob.enqueue(@mailer_class.to_s, @method_name, *@args)
  end
end

#deliver!Object



95
96
97
# File 'lib/que_mailer.rb', line 95

def deliver!
  actual_message.deliver
end

#deliver_at(time) ⇒ Object



85
86
87
88
89
# File 'lib/que_mailer.rb', line 85

def deliver_at(time)
  if @mailer_class.deliver?
    MailJob.enqueue(@mailer_class.to_s, @method_name, *@args, {:run_at => time})
  end
end

#deliver_in(time) ⇒ Object



91
92
93
# File 'lib/que_mailer.rb', line 91

def deliver_in(time)
  deliver_at(time.from_now)
end

#loggerObject



103
104
105
# File 'lib/que_mailer.rb', line 103

def logger
  @mailer_class.logger
end