Class: Resque::Mailer::MessageDecoy
- Inherits:
-
Object
- Object
- Resque::Mailer::MessageDecoy
show all
- Defined in:
- lib/resque_mailer.rb
Instance Method Summary
(collapse)
Constructor Details
- (MessageDecoy) initialize(mailer_class, method_name, *args)
A new instance of MessageDecoy
88
89
90
91
92
93
|
# File 'lib/resque_mailer.rb', line 88
def initialize(mailer_class, method_name, *args)
@mailer_class = mailer_class
@method_name = method_name
*@args = *args
actual_message if environment_excluded?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method_name, *args)
160
161
162
|
# File 'lib/resque_mailer.rb', line 160
def method_missing(method_name, *args)
actual_message.send(method_name, *args)
end
|
Instance Method Details
- (Object) actual_message
115
116
117
|
# File 'lib/resque_mailer.rb', line 115
def actual_message
@actual_message ||= @mailer_class.send(:new, @method_name, *@args).message
end
|
- (Object) current_env
99
100
101
102
103
104
105
|
# File 'lib/resque_mailer.rb', line 99
def current_env
if defined?(Rails)
::Resque::Mailer.current_env || ::Rails.env
else
::Resque::Mailer.current_env
end
end
|
- (Object) deliver
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/resque_mailer.rb', line 119
def deliver
return deliver! if environment_excluded?
if @mailer_class.deliver?
begin
resque.enqueue(@mailer_class, @method_name, *@args)
rescue Errno::ECONNREFUSED
logger.error "Unable to connect to Redis; falling back to synchronous mail delivery" if logger
deliver!
end
end
end
|
- (Object) deliver!
156
157
158
|
# File 'lib/resque_mailer.rb', line 156
def deliver!
actual_message.deliver
end
|
- (Object) deliver_at(time)
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/resque_mailer.rb', line 132
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, *@args)
end
end
|
- (Object) deliver_in(time)
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/resque_mailer.rb', line 144
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, *@args)
end
end
|
- (Boolean) environment_excluded?
107
108
109
|
# File 'lib/resque_mailer.rb', line 107
def environment_excluded?
!ActionMailer::Base.perform_deliveries || excluded_environment?(current_env)
end
|
- (Boolean) excluded_environment?(name)
111
112
113
|
# File 'lib/resque_mailer.rb', line 111
def excluded_environment?(name)
::Resque::Mailer.excluded_environments && ::Resque::Mailer.excluded_environments.include?(name.to_sym)
end
|
- (Object) logger
164
165
166
|
# File 'lib/resque_mailer.rb', line 164
def logger
@mailer_class.logger
end
|
- (Object) resque
95
96
97
|
# File 'lib/resque_mailer.rb', line 95
def resque
::Resque::Mailer.default_queue_target
end
|