mandrill_mailer 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3566de247b51759a56fc96545c27b53abdcbc3d
4
- data.tar.gz: 4d197d553c5336dd8012555a7b30c6144b95c6e6
3
+ metadata.gz: fcf5756ff80bf3ffe6dc8e5f7ce8e3696c2f0f02
4
+ data.tar.gz: 875412a838c62f216bc8d1aa918dc357d4d754eb
5
5
  SHA512:
6
- metadata.gz: db36a12377d1db8420e65176ac5dd22fe5401b0fd13277598306d25e1ab0fa6249e7bc0a0d42f0c13fb4b22023d1ab02a213ec076ade23e03ed33973c1e12c0a
7
- data.tar.gz: 93a04dfe2996c1680d24f9b83842d861a48c1fe9dbb2652aeca737de3b61f8b2e0a3dbd7565b095b9c2e7de5fbbc6eb5646f45f3237f5cbd33f31a7545c0d482
6
+ metadata.gz: adaed5b204343d14875024f50683af9863a97f0a7d7659d76022646ef80fe01d27a4f86c7eeb4b4f2596fadfda8ce56358f442cd6496e389fb1fb0bd94025397
7
+ data.tar.gz: bcd01547a76e87c47bcd17ce04d42685c2f8d3a9abd6ca35925db1229032047ddc0d256f0ed85688ca6cec3b05e84600898ccc3b26749070d9693b793a9c139b
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ rvm:
5
+ - 2.0.0-p598
6
+ - 2.1.0
7
+ - 2.2.0
8
+
9
+ script:
10
+ - bundle exec rspec spec/
11
+ branches:
12
+ only:
13
+ - master
14
+ notifications:
15
+ email: false
@@ -1,3 +1,10 @@
1
+ # 0.6.0
2
+ - [IMPROVEMENT] Allow for default `merge_vars` to be set on the mailer class so that every method inherits them, just like the existing default `from` and `from_name`.
3
+
4
+ # 0.5.2
5
+ - [IMPROVEMENT] Allow the mandrill api gem to be more flexible in the accepted version
6
+ which allows for the json gem to be updated internally.
7
+
1
8
  # 0.5.2
2
9
  - [IMPROVEMENT] Allow the mandrill api gem to be more flexible in the accepted version
3
10
  which allows for the json gem to be updated internally.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Mandrill Mailer
2
- [![Gem Version](http://img.shields.io/gem/v/mandrill_mailer.svg)](rubygems.org/gems/mandrill_mailer)
2
+ [![Build Status](https://travis-ci.org/renz45/mandrill_mailer.svg)](https://travis-ci.org/renz45/mandrill_mailer) [![Gem Version](http://img.shields.io/gem/v/mandrill_mailer.svg)](rubygems.org/gems/mandrill_mailer)
3
3
  [![Code Climate](http://img.shields.io/codeclimate/github/renz45/mandrill_mailer.svg)](https://codeclimate.com/github/renz45/mandrill_mailer)
4
- [![Dependencies](http://img.shields.io/gemnasium/renz45/mandrill_mailer.svg)](https://gemnasium.com/renz45/mandrill_mailer)
4
+ [![Dependencies](http://img.shields.io/gemnasium/renz45/mandrill_mailer.svg)](https://gemnasium.com/renz45/mandrill_mailer) [![Inline Documentation](http://inch-ci.org/github/renz45/mandrill_mailer.svg?branch=master)](http://inch-ci.org/github/renz45/mandrill_mailer)
5
5
 
6
6
  Inherit the MandrillMailer class in your existing Rails mailers to send transactional emails through Mandrill using their template-based emails.
7
7
 
@@ -99,6 +99,7 @@ end
99
99
  * `#default:`
100
100
  * `:from` - set the default from email address for the mailer
101
101
  * `:from_name` - set the default from name for the mailer. If not set, defaults to from email address. Setting :from_name in the .mandrill_mail overrides the default.
102
+ * `:merge_vars` - set some default `merge_vars` that will be sent with every mailer method (in `global_merge_vars` so there's no risk of collision with method-specific `merge_vars`.
102
103
 
103
104
  * `.mandrill_mail`
104
105
  * `:template`(required) - Template slug from within Mandrill (for backwards-compatibility, the template name may also be used but the immutable slug is preferred)
@@ -4,7 +4,9 @@
4
4
  # Example usage:
5
5
 
6
6
  # class InvitationMailer < MandrillMailer::TemplateMailer
7
- # default from: 'support@codeschool.com'
7
+ # default from: 'support@codeschool.com',
8
+ # from_name: 'Code School',
9
+ # merge_vars: { 'FOO' => 'Bar' }
8
10
 
9
11
  # def invite(invitation)
10
12
  # invitees = invitation.invitees.map { |invitee| { email: invitee.email, name: invitee.name } }
@@ -34,7 +36,9 @@
34
36
  # end
35
37
 
36
38
  # #default:
37
- # :from - set the default from email address for the mailer
39
+ # :from - set the default from email address for the mailer
40
+ # :from_name - set the default from name for the mailer
41
+ # :merge_vars - set the default merge vars for the mailer
38
42
 
39
43
  # .mandrill_mail
40
44
  # :template(required) - Template name from within Mandrill
@@ -123,12 +127,17 @@ module MandrillMailer
123
127
 
124
128
  # Public: Defaults for the mailer. Currently the only option is from:
125
129
  #
126
- # options - The Hash options used to refine the selection (default: {}):
127
- # :from - Default from email address
130
+ # options - The Hash options used to refine the selection (default: {}):
131
+ # :from - Default from email address
132
+ # :from_name - Default from name
133
+ # :merge_vars - Default merge vars
128
134
  #
129
135
  # Examples
130
136
  #
131
- # default from: 'foo@bar.com'
137
+ # default from: 'foo@bar.com',
138
+ # from_name: 'Foo Bar',
139
+ # merge_vars: {'FOO' => 'Bar'}
140
+ #
132
141
  #
133
142
  # Returns options
134
143
  def self.defaults
@@ -142,6 +151,7 @@ module MandrillMailer
142
151
  def self.default(args)
143
152
  @defaults ||= {}
144
153
  @defaults[:from] ||= 'example@email.com'
154
+ @defaults[:merge_vars] ||= {}
145
155
  @defaults.merge!(args)
146
156
  end
147
157
 
@@ -316,6 +326,8 @@ module MandrillMailer
316
326
 
317
327
  # convert a normal hash into the format mandrill needs
318
328
  def mandrill_args(args)
329
+ args = merge_default_merge_vars(args)
330
+
319
331
  return [] unless args
320
332
  args.map do |k,v|
321
333
  {'name' => k, 'content' => v}
@@ -326,10 +338,14 @@ module MandrillMailer
326
338
  return [] unless args
327
339
  args.map do |item|
328
340
  rcpt = item.keys[0]
329
- {'rcpt' => rcpt, 'vars' => mandrill_args(item.fetch(rcpt))}
341
+ { 'rcpt' => rcpt, 'vars' => mandrill_args(item.fetch(rcpt)) }
330
342
  end
331
343
  end
332
344
 
345
+ def merge_default_merge_vars(args)
346
+ self.class.defaults[:merge_vars].merge(args)
347
+ end
348
+
333
349
  # ensure only true or false is returned given arg
334
350
  def format_boolean(arg)
335
351
  arg ? true : false
@@ -168,7 +168,7 @@ module MandrillMailer
168
168
  "preserve_recipients" => args[:preserve_recipients],
169
169
  "bcc_address" => args[:bcc],
170
170
  "global_merge_vars" => mandrill_args(args[:vars]),
171
- "merge_vars" => mandrill_rcpt_args(args[:recipient_vars]),
171
+ "merge_vars" => mandrill_rcpt_args(args[:recipient_vars] || self.class.defaults[:merge_vars]),
172
172
  "tags" => args[:tags],
173
173
  "subaccount" => args[:subaccount],
174
174
  "google_analytics_domains" => args[:google_analytics_domains],
@@ -4,7 +4,9 @@
4
4
  # Example usage:
5
5
 
6
6
  # class InvitationMailer < MandrillMailer::TemplateMailer
7
- # default from: 'support@codeschool.com'
7
+ # default from: 'support@codeschool.com',
8
+ # from_name: 'Code School',
9
+ # merge_vars: { 'FOO' => 'Bar' }
8
10
 
9
11
  # def invite(invitation)
10
12
  # invitees = invitation.invitees.map { |invitee| { email: invitee.email, name: invitee.name } }
@@ -1,3 +1,3 @@
1
1
  module MandrillMailer
2
- VERSION = "0.5.2"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -360,35 +360,39 @@ describe MandrillMailer::TemplateMailer do
360
360
  describe 'defaults' do
361
361
  it 'should not share between different subclasses' do
362
362
  klassA = Class.new(MandrillMailer::TemplateMailer) do
363
- default from_name: 'ClassA'
363
+ default from_name: 'ClassA', merge_vars: { 'FOO' => 'Bar' }
364
364
  end
365
365
  klassB = Class.new(MandrillMailer::TemplateMailer) do
366
366
  default from_name: 'ClassB'
367
367
  end
368
368
 
369
369
  expect(klassA.mandrill_mail({vars: {}}).message['from_name']).to eq 'ClassA'
370
+ expect(klassA.mandrill_mail({vars: {}}).message['global_merge_vars']).to include({"name"=>"FOO", "content"=>"Bar"})
370
371
  expect(klassB.mandrill_mail({vars: {}}).message['from_name']).to eq 'ClassB'
372
+ expect(klassB.mandrill_mail({vars: {}}).message['global_merge_vars']).to_not include({"name"=>"FOO", "content"=>"Bar"})
371
373
  end
372
374
 
373
375
  it 'should use defaults from the parent class' do
374
376
  klassA = Class.new(MandrillMailer::TemplateMailer) do
375
- default from_name: 'ClassA'
377
+ default from_name: 'ClassA', merge_vars: { 'FOO' => 'Bar' }
376
378
  end
377
379
  klassB = Class.new(klassA) do
378
380
  end
379
381
 
380
- expect(klassB.mandrill_mail({vars:{}}).message['from_name']).to eq 'ClassA'
382
+ expect(klassB.mandrill_mail({vars: {}}).message['from_name']).to eq 'ClassA'
383
+ expect(klassB.mandrill_mail({vars: {}}).message['global_merge_vars']).to include({"name"=>"FOO", "content"=>"Bar"})
381
384
  end
382
385
 
383
386
  it 'should allow overriding defaults from the parent' do
384
387
  klassA = Class.new(MandrillMailer::TemplateMailer) do
385
- default from_name: 'ClassA'
388
+ default from_name: 'ClassA', merge_vars: { 'FOO' => 'Bar' }
386
389
  end
387
390
  klassB = Class.new(klassA) do
388
- default from_name: 'ClassB'
391
+ default from_name: 'ClassB', merge_vars: { 'FOO' => 'Boo' }
389
392
  end
390
393
 
391
- expect(klassB.mandrill_mail({vars:{}}).message['from_name']).to eq 'ClassB'
394
+ expect(klassB.mandrill_mail({vars: {}}).message['from_name']).to eq 'ClassB'
395
+ expect(klassB.mandrill_mail({vars: {}}).message['global_merge_vars']).to include({"name"=>"FOO", "content"=>"Boo"})
392
396
  end
393
397
  end
394
398
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mandrill_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Rensel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-22 00:00:00.000000000 Z
11
+ date: 2015-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -89,6 +89,7 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
91
  - ".rspec"
92
+ - ".travis.yml"
92
93
  - CHANGELOG.md
93
94
  - Gemfile
94
95
  - README.md