adzap-ar_mailer 2.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,7 @@
1
+ = 2.1.0
2
+
3
+ * Switched to using a Rails generator for migration and model files. The ar_sendmail options have been removed.
4
+
1
5
  = 2.0.2
2
6
 
3
7
  * Bugs fixed
@@ -54,22 +54,24 @@ Go to your Rails project:
54
54
 
55
55
  $ cd your_rails_project
56
56
 
57
- Create a new migration:
57
+ Create the migration and model:
58
58
 
59
- $ ar_sendmail --create-migration
59
+ This shows the options which are only the model name, which defaults to Email
60
60
 
61
- You'll need to redirect this into a file. If you want a different name
62
- provide the --table-name option.
61
+ ./script/generate ar_mailer -h
63
62
 
64
- Create a new model:
63
+ Then run with defaults
65
64
 
66
- $ ar_sendmail --create-model
65
+ ./script/generate ar_mailer
67
66
 
68
- You'll need to redirect this into a file. If you want a different name
69
- provide the --table-name option.
67
+ Or specify a custom model name
70
68
 
71
- You'll need to be sure to set the From address for your emails. Something
72
- like:
69
+ ./script/generate ar_mailer Newsletter
70
+
71
+ See Alternate Mail Storage if you use a custom model name
72
+
73
+ In your mailer class methods you must be sure to set the From address for your emails.
74
+ Something like:
73
75
 
74
76
  def list_send(recipient)
75
77
  from 'no_reply@example.com'
@@ -101,8 +103,11 @@ See <tt>ar_sendmail -h</tt> for full details.
101
103
 
102
104
  === Alternate Mail Storage
103
105
 
104
- If you want to set the ActiveRecord model that emails will be stored in,
105
- see ActionMailer::Base.email_class=
106
+ By default ar_mailer assumes you are using an ActiveRecord model called
107
+ Email to store the emails created before sending. If you want to change
108
+ this you alter it in an intializer like so:
109
+
110
+ ActionMailer::Base.email_class = Newsletter
106
111
 
107
112
  === A Word on TLS
108
113
 
@@ -37,16 +37,13 @@ module ActionMailer; end # :nodoc:
37
37
  # The interesting options are:
38
38
  # * --daemon
39
39
  # * --mailq
40
- # * --create-migration
41
- # * --create-model
42
- # * --table-name
43
40
 
44
41
  class ActionMailer::ARSendmail
45
42
 
46
43
  ##
47
44
  # The version of ActionMailer::ARSendmail you are running.
48
45
 
49
- VERSION = '2.0.2'
46
+ VERSION = '2.1.0'
50
47
 
51
48
  ##
52
49
  # Maximum number of times authentication will be consecutively retried
@@ -98,41 +95,6 @@ class ActionMailer::ARSendmail
98
95
  end
99
96
  end
100
97
 
101
- ##
102
- # Creates a new migration using +table_name+ and prints it on stdout.
103
-
104
- def self.create_migration(table_name)
105
- require 'active_support'
106
- puts <<-EOF
107
- class Create#{table_name.classify} < ActiveRecord::Migration
108
- def self.up
109
- create_table :#{table_name.tableize} do |t|
110
- t.column :from, :string
111
- t.column :to, :string
112
- t.column :last_send_attempt, :integer, :default => 0
113
- t.column :mail, :text
114
- t.column :created_on, :datetime
115
- end
116
- end
117
-
118
- def self.down
119
- drop_table :#{table_name.tableize}
120
- end
121
- end
122
- EOF
123
- end
124
-
125
- ##
126
- # Creates a new model using +table_name+ and prints it on stdout.
127
-
128
- def self.create_model(table_name)
129
- require 'active_support'
130
- puts <<-EOF
131
- class #{table_name.classify} < ActiveRecord::Base
132
- end
133
- EOF
134
- end
135
-
136
98
  ##
137
99
  # Prints a list of unsent emails and the last delivery attempt, if any.
138
100
  #
@@ -140,9 +102,8 @@ end
140
102
  # known. See http://api.rubyonrails.org/classes/ActiveRecord/Timestamp.html
141
103
  # to learn how to enable ActiveRecord::Timestamp.
142
104
 
143
- def self.mailq(table_name)
144
- klass = table_name.split('::').inject(Object) { |k,n| k.const_get n }
145
- emails = klass.find :all
105
+ def self.mailq
106
+ emails = ActionMailer::Base.email_class.find :all
146
107
 
147
108
  if emails.empty? then
148
109
  puts "Mail queue is empty"
@@ -191,7 +152,6 @@ end
191
152
  options[:MaxAge] = 86400 * 7
192
153
  options[:Once] = false
193
154
  options[:RailsEnv] = ENV['RAILS_ENV']
194
- options[:TableName] = 'Email'
195
155
  options[:Pidfile] = options[:Chdir] + '/log/ar_sendmail.pid'
196
156
 
197
157
  opts = OptionParser.new do |opts|
@@ -253,18 +213,6 @@ end
253
213
  opts.separator ''
254
214
  opts.separator 'Setup Options:'
255
215
 
256
- opts.on( "--create-migration",
257
- "Prints a migration to add an Email table",
258
- "to stdout") do |create|
259
- options[:Migrate] = true
260
- end
261
-
262
- opts.on( "--create-model",
263
- "Prints a model for an Email ActiveRecord",
264
- "object to stdout") do |create|
265
- options[:Model] = true
266
- end
267
-
268
216
  opts.separator ''
269
217
  opts.separator 'Generic Options:'
270
218
 
@@ -282,14 +230,6 @@ end
282
230
  options[:RailsEnv] = env
283
231
  end
284
232
 
285
- opts.on("-t", "--table-name TABLE_NAME",
286
- "Name of table holding emails",
287
- "Used for both sendmail and",
288
- "migration creation",
289
- "Default: #{options[:TableName]}") do |name|
290
- options[:TableName] = name
291
- end
292
-
293
233
  opts.on("-v", "--[no-]verbose",
294
234
  "Be verbose",
295
235
  "Default: #{options[:Verbose]}") do |verbose|
@@ -310,8 +250,6 @@ end
310
250
 
311
251
  opts.parse! args
312
252
 
313
- return options if options.include? :Migrate or options.include? :Model
314
-
315
253
  ENV['RAILS_ENV'] = options[:RailsEnv]
316
254
 
317
255
  Dir.chdir options[:Chdir] do
@@ -321,7 +259,7 @@ end
321
259
  usage opts, <<-EOF
322
260
  #{name} must be run from a Rails application's root to deliver email.
323
261
  #{Dir.pwd} does not appear to be a Rails application root.
324
- EOF
262
+ EOF
325
263
  end
326
264
  end
327
265
 
@@ -334,14 +272,8 @@ end
334
272
  def self.run(args = ARGV)
335
273
  options = process_args args
336
274
 
337
- if options.include? :Migrate then
338
- create_migration options[:TableName]
339
- exit
340
- elsif options.include? :Model then
341
- create_model options[:TableName]
342
- exit
343
- elsif options.include? :MailQ then
344
- mailq options[:TableName]
275
+ if options.include? :MailQ then
276
+ mailq
345
277
  exit
346
278
  end
347
279
 
@@ -396,18 +328,16 @@ end
396
328
  # Valid options are:
397
329
  # <tt>:BatchSize</tt>:: Maximum number of emails to send per delay
398
330
  # <tt>:Delay</tt>:: Delay between deliver attempts
399
- # <tt>:TableName</tt>:: Table name that stores the emails
400
331
  # <tt>:Once</tt>:: Only attempt to deliver emails once when run is called
401
332
  # <tt>:Verbose</tt>:: Be verbose.
402
333
 
403
334
  def initialize(options = {})
404
335
  options[:Delay] ||= 60
405
- options[:TableName] ||= 'Email'
406
336
  options[:MaxAge] ||= 86400 * 7
407
337
 
408
338
  @batch_size = options[:BatchSize]
409
339
  @delay = options[:Delay]
410
- @email_class = options[:TableName].constantize
340
+ @email_class = ActionMailer::Base.email_class
411
341
  @once = options[:Once]
412
342
  @verbose = options[:Verbose]
413
343
  @max_age = options[:MaxAge]
@@ -77,6 +77,7 @@ class ActionMailer::Base
77
77
  @server_settings = {}
78
78
 
79
79
  class << self
80
+ cattr_accessor :email_class
80
81
  attr_accessor :delivery_method
81
82
  end
82
83
 
@@ -94,6 +95,7 @@ class ActionMailer::Base
94
95
 
95
96
  def self.reset
96
97
  server_settings.clear
98
+ self.email_class = Email
97
99
  end
98
100
 
99
101
  def self.server_settings
@@ -184,6 +186,8 @@ end
184
186
 
185
187
  Mail = Email
186
188
 
189
+ class Newsletter < Email; end
190
+
187
191
  class String
188
192
  def classify
189
193
  self
@@ -33,45 +33,6 @@ class TestARSendmail < MiniTest::Unit::TestCase
33
33
  $".delete 'config/environment.rb' unless @include_c_e
34
34
  end
35
35
 
36
- def test_class_create_migration
37
- out, = capture_io do
38
- ActionMailer::ARSendmail.create_migration 'Mail'
39
- end
40
-
41
- expected = <<-EOF
42
- class CreateMail < ActiveRecord::Migration
43
- def self.up
44
- create_table :mail do |t|
45
- t.column :from, :string
46
- t.column :to, :string
47
- t.column :last_send_attempt, :integer, :default => 0
48
- t.column :mail, :text
49
- t.column :created_on, :datetime
50
- end
51
- end
52
-
53
- def self.down
54
- drop_table :mail
55
- end
56
- end
57
- EOF
58
-
59
- assert_equal expected, out
60
- end
61
-
62
- def test_class_create_model
63
- out, = capture_io do
64
- ActionMailer::ARSendmail.create_model 'Mail'
65
- end
66
-
67
- expected = <<-EOF
68
- class Mail < ActiveRecord::Base
69
- end
70
- EOF
71
-
72
- assert_equal expected, out
73
- end
74
-
75
36
  def test_class_mailq
76
37
  Email.create :from => nobody, :to => 'recip@h1.example.com',
77
38
  :mail => 'body0'
@@ -83,7 +44,7 @@ end
83
44
  last.last_send_attempt = last_attempt_time.to_i
84
45
 
85
46
  out, err = capture_io do
86
- ActionMailer::ARSendmail.mailq 'Email'
47
+ ActionMailer::ARSendmail.mailq
87
48
  end
88
49
 
89
50
  expected = <<-EOF
@@ -107,7 +68,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
107
68
 
108
69
  def test_class_mailq_empty
109
70
  out, err = capture_io do
110
- ActionMailer::ARSendmail.mailq 'Email'
71
+ ActionMailer::ARSendmail.mailq
111
72
  end
112
73
 
113
74
  assert_equal "Mail queue is empty\n", out
@@ -123,14 +84,22 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
123
84
  assert_equal nil, @sm.batch_size
124
85
 
125
86
  @sm = ActionMailer::ARSendmail.new :Delay => 75, :Verbose => true,
126
- :TableName => 'Object', :Once => true,
127
- :BatchSize => 1000
87
+ :Once => true, :BatchSize => 1000
128
88
 
129
89
  assert_equal 75, @sm.delay
130
- assert_equal Object, @sm.email_class
90
+ assert_equal Email, @sm.email_class
131
91
  assert_equal true, @sm.once
132
92
  assert_equal true, @sm.verbose
133
93
  assert_equal 1000, @sm.batch_size
94
+
95
+ ActionMailer::Base.email_class = Newsletter
96
+ @sm = ActionMailer::ARSendmail.new
97
+
98
+ assert_equal 60, @sm.delay
99
+ assert_equal Newsletter, @sm.email_class
100
+ assert_equal nil, @sm.once
101
+ assert_equal nil, @sm.verbose
102
+ assert_equal nil, @sm.batch_size
134
103
  end
135
104
 
136
105
  def test_class_parse_args_batch_size
@@ -241,28 +210,6 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
241
210
  assert_equal 86400, options[:MaxAge]
242
211
  end
243
212
 
244
- def test_class_parse_args_migration
245
- options = ActionMailer::ARSendmail.process_args []
246
- refute_includes options, :Migration
247
-
248
- argv = %w[--create-migration]
249
-
250
- options = ActionMailer::ARSendmail.process_args argv
251
-
252
- assert_equal true, options[:Migrate]
253
- end
254
-
255
- def test_class_parse_args_model
256
- options = ActionMailer::ARSendmail.process_args []
257
- refute_includes options, :Model
258
-
259
- argv = %w[--create-model]
260
-
261
- options = ActionMailer::ARSendmail.process_args argv
262
-
263
- assert_equal true, options[:Model]
264
- end
265
-
266
213
  def test_class_parse_args_no_config_environment
267
214
  $".delete 'config/environment.rb'
268
215
 
@@ -276,35 +223,6 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
276
223
  $" << 'config/environment.rb' if @include_c_e
277
224
  end
278
225
 
279
- def test_class_parse_args_no_config_environment_migrate
280
- $".delete 'config/environment.rb'
281
-
282
- out, err = capture_io do
283
- ActionMailer::ARSendmail.process_args %w[--create-migration]
284
- end
285
-
286
- assert true # count
287
-
288
- ensure
289
- $" << 'config/environment.rb' if @include_c_e
290
- end
291
-
292
- def test_class_parse_args_no_config_environment_model
293
- $".delete 'config/environment.rb'
294
-
295
- out, err = capture_io do
296
- ActionMailer::ARSendmail.process_args %w[--create-model]
297
- end
298
-
299
- assert true # count
300
-
301
- rescue SystemExit
302
- flunk 'Should not exit'
303
-
304
- ensure
305
- $" << 'config/environment.rb' if @include_c_e
306
- end
307
-
308
226
  def test_class_parse_args_once
309
227
  argv = %w[-o]
310
228
 
@@ -319,20 +237,6 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
319
237
  assert_equal true, options[:Once]
320
238
  end
321
239
 
322
- def test_class_parse_args_table_name
323
- argv = %w[-t Email]
324
-
325
- options = ActionMailer::ARSendmail.process_args argv
326
-
327
- assert_equal 'Email', options[:TableName]
328
-
329
- argv = %w[--table-name=Email]
330
-
331
- options = ActionMailer::ARSendmail.process_args argv
332
-
333
- assert_equal 'Email', options[:TableName]
334
- end
335
-
336
240
  def test_class_usage
337
241
  out, err = capture_io do
338
242
  assert_raises SystemExit do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adzap-ar_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-04-17 00:00:00 -07:00
13
+ date: 2009-06-23 00:00:00 -07:00
14
14
  default_executable: ar_sendmail
15
15
  dependencies: []
16
16