Class: Resque::Mailer::MessageDecoy
- Inherits:
-
Object
- Object
- Resque::Mailer::MessageDecoy
show all
- Defined in:
- lib/resque_mailer.rb
Instance Method Summary
collapse
Constructor Details
#initialize(mailer_class, method_name, *args) ⇒ MessageDecoy
Returns a new instance of MessageDecoy.
105
106
107
108
109
110
111
|
# File 'lib/resque_mailer.rb', line 105
def initialize(mailer_class, method_name, *args)
@mailer_class = mailer_class
@method_name = method_name
*@args = *args
@serialized_args = ::Resque::Mailer.argument_serializer.serialize(*args)
actual_message if environment_excluded?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
192
193
194
|
# File 'lib/resque_mailer.rb', line 192
def method_missing(method_name, *args)
actual_message.send(method_name, *args)
end
|
Instance Method Details
#actual_message ⇒ Object
133
134
135
|
# File 'lib/resque_mailer.rb', line 133
def actual_message
@actual_message ||= ::Resque::Mailer.prepare_message(@mailer_class, @method_name, *@args)
end
|
#deliver ⇒ Object
Also known as:
deliver_now
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/resque_mailer.rb', line 137
def deliver
return deliver! if environment_excluded?
if @mailer_class.deliver?
begin
resque.enqueue(@mailer_class, @method_name, @serialized_args)
rescue Errno::ECONNREFUSED, Redis::CannotConnectError
logger.error "Unable to connect to Redis; falling back to synchronous mail delivery" if logger
deliver!
end
end
end
|
#deliver! ⇒ Object
Also known as:
deliver_now!
183
184
185
186
187
188
189
|
# File 'lib/resque_mailer.rb', line 183
def deliver!
if actual_message.respond_to?(:deliver_now)
actual_message.deliver_now
else
actual_message.deliver
end
end
|
#deliver_at(time) ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/resque_mailer.rb', line 151
def deliver_at(time)
return deliver! if environment_excluded?
unless resque.respond_to? :enqueue_at
raise "You need to install resque-scheduler to use deliver_at"
end
if @mailer_class.deliver?
resque.enqueue_at(time, @mailer_class, @method_name, @serialized_args)
end
end
|
#deliver_in(time) ⇒ Object
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/resque_mailer.rb', line 163
def deliver_in(time)
return deliver! if environment_excluded?
unless resque.respond_to? :enqueue_in
raise "You need to install resque-scheduler to use deliver_in"
end
if @mailer_class.deliver?
resque.enqueue_in(time, @mailer_class, @method_name, @serialized_args)
end
end
|
#environment_excluded? ⇒ Boolean
125
126
127
|
# File 'lib/resque_mailer.rb', line 125
def environment_excluded?
!ActionMailer::Base.perform_deliveries || excluded_environment?(current_env)
end
|
#excluded_environment?(name) ⇒ Boolean
#logger ⇒ Object
200
201
202
|
# File 'lib/resque_mailer.rb', line 200
def logger
@mailer_class.logger
end
|
#respond_to?(method_name, *args) ⇒ Boolean
196
197
198
|
# File 'lib/resque_mailer.rb', line 196
def respond_to?(method_name, *args)
super || actual_message.respond_to?(method_name, *args)
end
|
#unschedule_delivery ⇒ Object
175
176
177
178
179
180
181
|
# File 'lib/resque_mailer.rb', line 175
def unschedule_delivery
unless resque.respond_to? :remove_delayed
raise "You need to install resque-scheduler to use unschedule_delivery"
end
resque.remove_delayed(@mailer_class, @method_name, @serialized_args)
end
|