hanami-mailer 0.2.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb739b22196267893812b43fcf2c2e7b37185e3f
4
- data.tar.gz: d0686236004144e85a9a1d1bac67447b3f344acf
3
+ metadata.gz: f6bc33d0ec8a8e972be6d7de97473a6508616459
4
+ data.tar.gz: 5b79dacf8ff839f77fc066210673087f250ec52c
5
5
  SHA512:
6
- metadata.gz: 418c209b8b97286b1076579537bccb7cec64bf51abfaeb881a10ff374601bb564630aea514b1eb17b176427c5a51d1723d9833edf8cba03f348a9f8427cb7803
7
- data.tar.gz: d495d3926cb1afe2f1fbb5769e262db19daa7296647c00ebf15232d156f6f8fb3b39c81f8116cd7d34ec8d1bc055b8b76c15742f807e23e2e62d7749cee5c307
6
+ metadata.gz: 13d2f8eafab2fc9a87bae04276f30d1e1e1bf24c05c630aa80d2538699f4690ab8ec9eeb4ee68845a4068fdd865abe47ece7df925efc909dc412c6749ef98771
7
+ data.tar.gz: b8805778f4496eec6961429d3493478076c49142d757faa5a9905b71baada249d4c9ef32cf7a5711035f10bf9edf1c18c0417499d54b15c4a7740017aa92f030
@@ -1,6 +1,14 @@
1
1
  # Hanami::Router
2
2
  Mail for Ruby applications
3
3
 
4
+ ## v0.3.0 - 2016-07-22
5
+ ### Added
6
+ – [Anton Dabydov] Blind carbon copy (bcc) option
7
+ – [Anton Dabydov] Carbon copy (cc) option
8
+
9
+ ### Changed
10
+ – [Luca Guidi] Drop support for Ruby 2.0 and 2.1
11
+
4
12
  ## v0.2.0 - 2016-01-22
5
13
  ### Changed
6
14
  - [Luca Guidi] Renamed the project
data/README.md CHANGED
@@ -66,7 +66,7 @@ A mailer with `.to` and `.from` addresses and mailer delivery:
66
66
  ```ruby
67
67
  require 'hanami/mailer'
68
68
 
69
- Hanami::Mailer.configuration do
69
+ Hanami::Mailer.configure do
70
70
  delivery_method :smtp,
71
71
  address: "smtp.gmail.com",
72
72
  port: 587,
@@ -80,8 +80,11 @@ end.load!
80
80
  class WelcomeMailer
81
81
  include Hanami::Mailer
82
82
 
83
- from 'noreply@sender.com'
84
- to 'noreply@recipient.com'
83
+ from 'noreply@sender.com'
84
+ to 'noreply@recipient.com'
85
+ cc 'cc@sender.com'
86
+ bcc 'alice@example.com'
87
+
85
88
  subject 'Welcome'
86
89
  end
87
90
 
@@ -90,15 +93,13 @@ WelcomeMailer.deliver
90
93
 
91
94
  ### Locals
92
95
 
93
- The set of objects passed in the `deliver` call are called `locals` and are avaliable inside the mailer and the template.
96
+ The set of objects passed in the `deliver` call are called `locals` and are available inside the mailer and the template.
94
97
 
95
98
  ```ruby
96
99
  require 'hanami/mailer'
97
100
 
98
- User = Struct.new(:name, :username)
99
- user = User.new('Luca', 'jodosha')
100
-
101
- Hanami::Mailer.load!
101
+ User = Struct.new(:name, :username, :email)
102
+ luca = User.new('Luca', 'jodosha', 'luca@jodosha.com')
102
103
 
103
104
  class WelcomeMailer
104
105
  include Hanami::Mailer
@@ -114,7 +115,7 @@ class WelcomeMailer
114
115
  end
115
116
  end
116
117
 
117
- InvoiceMailer.deliver(user: luca)
118
+ WelcomeMailer.deliver(user: luca)
118
119
  ```
119
120
 
120
121
  The corresponding `erb` file:
@@ -8,22 +8,22 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ['Luca Guidi', 'Ines Coelho', 'Rosa Faria']
9
9
  spec.email = ['me@lucaguidi.com', 'ines.opcoelho@gmail.com', 'rosa1853@live.com']
10
10
 
11
- spec.summary = %q{Mail for Ruby applications.}
12
- spec.description = %q{Mail for Ruby applications and Hanami mailers}
11
+ spec.summary = 'Mail for Ruby applications.'
12
+ spec.description = 'Mail for Ruby applications and Hanami mailers'
13
13
  spec.homepage = 'http://hanamirb.org'
14
14
  spec.license = 'MIT'
15
15
 
16
- spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md hanami-mailer.gemspec`.split($/)
16
+ spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md hanami-mailer.gemspec`.split($/) # rubocop:disable Style/SpecialGlobalVars
17
17
  spec.bindir = 'exe'
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ['lib']
20
- spec.required_ruby_version = '>= 2.0.0'
20
+ spec.required_ruby_version = '>= 2.2.0'
21
21
 
22
- spec.add_dependency 'hanami-utils', '~> 0.7'
22
+ spec.add_dependency 'hanami-utils', '~> 0.8'
23
23
  spec.add_dependency 'tilt', '~> 2.0', '>= 2.0.1'
24
24
  spec.add_dependency 'mail', '~> 2.5'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 1.10'
27
- spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rake', '~> 11'
28
28
  spec.add_development_dependency 'minitest', '~> 5.7'
29
29
  end
@@ -1 +1 @@
1
- require 'hanami/mailer'
1
+ require 'hanami/mailer' # rubocop:disable Style/FileName
@@ -73,7 +73,7 @@ module Hanami
73
73
  #
74
74
  # @see http://www.ruby-doc.org/core/Module.html#method-i-included
75
75
  def self.included(base)
76
- conf = self.configuration
76
+ conf = configuration
77
77
  conf.add_mailer(base)
78
78
 
79
79
  base.class_eval do
@@ -134,7 +134,7 @@ module Hanami
134
134
  # <tt>Signup::Welcome.deliver(format: :txt)</tt>
135
135
  #
136
136
  # All the given locals, excepted the reserved ones (<tt>:format</tt> and
137
- # <tt>charset</tt>), are avaliable as rendering context for the templates.
137
+ # <tt>charset</tt>), are available as rendering context for the templates.
138
138
  #
139
139
  # @param locals [Hash] a set of objects that acts as context for the rendering
140
140
  # @option :format [Symbol] specify format to deliver
@@ -197,19 +197,8 @@ module Hanami
197
197
  def initialize(locals = {})
198
198
  @locals = locals
199
199
  @format = locals.fetch(:format, nil)
200
- @charset = charset = locals.fetch(:charset, self.class.configuration.default_charset)
201
- @mail = Mail.new.tap do |m|
202
- m.from = __dsl(:from)
203
- m.to = __dsl(:to)
204
- m.subject = __dsl(:subject)
205
-
206
- m.charset = charset
207
- m.html_part = __part(:html)
208
- m.text_part = __part(:txt)
209
-
210
- m.delivery_method(*Hanami::Mailer.configuration.delivery_method)
211
- end
212
-
200
+ @charset = locals.fetch(:charset, self.class.configuration.default_charset)
201
+ @mail = build
213
202
  prepare
214
203
  end
215
204
 
@@ -286,6 +275,26 @@ module Hanami
286
275
 
287
276
  private
288
277
 
278
+ # rubocop:disable Metrics/MethodLength
279
+ # rubocop:disable Metrics/AbcSize
280
+ def build
281
+ Mail.new.tap do |m|
282
+ m.from = __dsl(:from)
283
+ m.to = __dsl(:to)
284
+ m.cc = __dsl(:cc)
285
+ m.bcc = __dsl(:bcc)
286
+ m.subject = __dsl(:subject)
287
+
288
+ m.charset = charset
289
+ m.html_part = __part(:html)
290
+ m.text_part = __part(:txt)
291
+
292
+ m.delivery_method(*Hanami::Mailer.configuration.delivery_method)
293
+ end
294
+ end
295
+ # rubocop:enable Metrics/MethodLength
296
+ # rubocop:enable Metrics/AbcSize
297
+
289
298
  # @private
290
299
  # @since 0.1.0
291
300
  def __dsl(method_name)
@@ -301,7 +310,7 @@ module Hanami
301
310
  # @since 0.1.0
302
311
  def __part(format)
303
312
  Mail::Part.new.tap do |part|
304
- part.content_type = "#{ CONTENT_TYPES.fetch(format) }; charset=#{ charset }"
313
+ part.content_type = "#{CONTENT_TYPES.fetch(format)}; charset=#{charset}"
305
314
  part.body = render(format)
306
315
  end if __part?(format)
307
316
  end
@@ -144,7 +144,7 @@ module Hanami
144
144
  #
145
145
  # @see Hanami::Mailer.configure
146
146
  def prepare(&blk)
147
- if block_given?
147
+ if block_given? # rubocop:disable Style/GuardClause
148
148
  @modules.push(blk)
149
149
  else
150
150
  raise ArgumentError.new('Please provide a block')
@@ -191,7 +191,7 @@ module Hanami
191
191
  @modules = []
192
192
  end
193
193
 
194
- alias_method :unload!, :reset!
194
+ alias unload! reset!
195
195
 
196
196
  # Copy the configuration for the given mailer
197
197
  #
@@ -283,6 +283,7 @@ module Hanami
283
283
  end
284
284
 
285
285
  protected
286
+
286
287
  # @api private
287
288
  # @since 0.1.0
288
289
  attr_writer :root
@@ -7,6 +7,18 @@ module Hanami
7
7
  #
8
8
  # @since 0.1.0
9
9
  module Dsl
10
+ # @since 0.3.0
11
+ # @api private
12
+ def self.extended(base)
13
+ base.class_eval do
14
+ @from = nil
15
+ @to = nil
16
+ @cc = nil
17
+ @bcc = nil
18
+ @subject = nil
19
+ end
20
+ end
21
+
10
22
  # Set the template name IF it differs from the convention.
11
23
  #
12
24
  # For a given mailer named <tt>Signup::Welcome</tt> it will look for
@@ -129,6 +141,184 @@ module Hanami
129
141
  end
130
142
  end
131
143
 
144
+ # Sets the cc (carbon copy) for mail messages
145
+ #
146
+ # It accepts a hardcoded value as a string or array of strings.
147
+ # For dynamic values, you can specify a symbol that represents an instance
148
+ # method.
149
+ #
150
+ # This value is optional.
151
+ #
152
+ # When a value is given, it specifies the cc for the email.
153
+ # When a value is not given, it returns the cc of the email.
154
+ #
155
+ # This is part of a DSL, for this reason when this method is called with
156
+ # an argument, it will set the corresponding class variable. When
157
+ # called without, it will return the already set value, or the default.
158
+ #
159
+ # @overload cc(value)
160
+ # Sets the cc
161
+ # @param value [String, Array, Symbol] the hardcoded value or method name
162
+ # @return [NilClass]
163
+ #
164
+ # @overload cc
165
+ # Returns the cc
166
+ # @return [String, Array, Symbol] the recipient
167
+ #
168
+ # @since 0.3.0
169
+ #
170
+ # @example Hardcoded value (String)
171
+ # require 'hanami/mailer'
172
+ #
173
+ # class WelcomeMailer
174
+ # include Hanami::Mailer
175
+ #
176
+ # to "user@example.com"
177
+ # cc "other.user@example.com"
178
+ # end
179
+ #
180
+ # @example Hardcoded value (Array)
181
+ # require 'hanami/mailer'
182
+ #
183
+ # class WelcomeMailer
184
+ # include Hanami::Mailer
185
+ #
186
+ # to ["user-1@example.com", "user-2@example.com"]
187
+ # cc ["other.user-1@example.com", "other.user-2@example.com"]
188
+ # end
189
+ #
190
+ # @example Method (Symbol)
191
+ # require 'hanami/mailer'
192
+ #
193
+ # class WelcomeMailer
194
+ # include Hanami::Mailer
195
+ # to "user@example.com"
196
+ # cc :email_address
197
+ #
198
+ # private
199
+ #
200
+ # def email_address
201
+ # user.email
202
+ # end
203
+ # end
204
+ #
205
+ # other_user = User.new(name: 'L')
206
+ # WelcomeMailer.deliver(user: other_user)
207
+ #
208
+ # @example Method that returns a collection of recipients
209
+ # require 'hanami/mailer'
210
+ #
211
+ # class WelcomeMailer
212
+ # include Hanami::Mailer
213
+ # to "user@example.com"
214
+ # cc :recipients
215
+ #
216
+ # private
217
+ #
218
+ # def recipients
219
+ # users.map(&:email)
220
+ # end
221
+ # end
222
+ #
223
+ # other_users = [User.new(name: 'L'), User.new(name: 'MG')]
224
+ # WelcomeMailer.deliver(users: other_users)
225
+ def cc(value = nil)
226
+ if value.nil?
227
+ @cc
228
+ else
229
+ @cc = value
230
+ end
231
+ end
232
+
233
+ # Sets the bcc (blind carbon copy) for mail messages
234
+ #
235
+ # It accepts a hardcoded value as a string or array of strings.
236
+ # For dynamic values, you can specify a symbol that represents an instance
237
+ # method.
238
+ #
239
+ # This value is optional.
240
+ #
241
+ # When a value is given, it specifies the bcc for the email.
242
+ # When a value is not given, it returns the bcc of the email.
243
+ #
244
+ # This is part of a DSL, for this reason when this method is called with
245
+ # an argument, it will set the corresponding class variable. When
246
+ # called without, it will return the already set value, or the default.
247
+ #
248
+ # @overload bcc(value)
249
+ # Sets the bcc
250
+ # @param value [String, Array, Symbol] the hardcoded value or method name
251
+ # @return [NilClass]
252
+ #
253
+ # @overload bcc
254
+ # Returns the bcc
255
+ # @return [String, Array, Symbol] the recipient
256
+ #
257
+ # @since 0.3.0
258
+ #
259
+ # @example Hardcoded value (String)
260
+ # require 'hanami/mailer'
261
+ #
262
+ # class WelcomeMailer
263
+ # include Hanami::Mailer
264
+ #
265
+ # to "user@example.com"
266
+ # bcc "other.user@example.com"
267
+ # end
268
+ #
269
+ # @example Hardcoded value (Array)
270
+ # require 'hanami/mailer'
271
+ #
272
+ # class WelcomeMailer
273
+ # include Hanami::Mailer
274
+ #
275
+ # to ["user-1@example.com", "user-2@example.com"]
276
+ # bcc ["other.user-1@example.com", "other.user-2@example.com"]
277
+ # end
278
+ #
279
+ # @example Method (Symbol)
280
+ # require 'hanami/mailer'
281
+ #
282
+ # class WelcomeMailer
283
+ # include Hanami::Mailer
284
+ # to "user@example.com"
285
+ # bcc :email_address
286
+ #
287
+ # private
288
+ #
289
+ # def email_address
290
+ # user.email
291
+ # end
292
+ # end
293
+ #
294
+ # other_user = User.new(name: 'L')
295
+ # WelcomeMailer.deliver(user: other_user)
296
+ #
297
+ # @example Method that returns a collection of recipients
298
+ # require 'hanami/mailer'
299
+ #
300
+ # class WelcomeMailer
301
+ # include Hanami::Mailer
302
+ # to "user@example.com"
303
+ # bcc :recipients
304
+ #
305
+ # private
306
+ #
307
+ # def recipients
308
+ # users.map(&:email)
309
+ # end
310
+ # end
311
+ #
312
+ # other_users = [User.new(name: 'L'), User.new(name: 'MG')]
313
+ # WelcomeMailer.deliver(users: other_users)
314
+ def bcc(value = nil)
315
+ if value.nil?
316
+ @bcc
317
+ else
318
+ @bcc = value
319
+ end
320
+ end
321
+
132
322
  # Sets the recipient for mail messages
133
323
  #
134
324
  # It accepts a hardcoded value as a string or array of strings.
@@ -26,6 +26,7 @@ module Hanami
26
26
  end
27
27
 
28
28
  private
29
+
29
30
  # @since 0.1.0
30
31
  # @api private
31
32
  def compile!(namespace)
@@ -44,7 +45,7 @@ module Hanami
44
45
  # @since 0.1.0
45
46
  # @api private
46
47
  def replace!(token)
47
- @name.gsub!(%r{\A#{ token }#{ NAMESPACE_SEPARATOR }}, '')
48
+ @name.gsub!(/\A#{token}#{NAMESPACE_SEPARATOR}/, '')
48
49
  end
49
50
  end
50
51
  end
@@ -69,11 +69,11 @@ module Hanami
69
69
  # Hanami::Mailer::Rendering::TemplatesFinder.new(Mailers::Welcome).find
70
70
  # # => [#<Hanami::Mailer::Template:0x007f8a0a86a970 ... @file="/path/to/templates/welcome.html.erb">]
71
71
  def find
72
- templates = Hash.new
72
+ templates = Hash[]
73
73
  _find.map do |template|
74
74
  name = File.basename(template)
75
- format = (( name.split(".") )[-2]).to_sym
76
- templates[ format ] = Mailer::Template.new(template)
75
+ format = (name.split('.')[-2]).to_sym
76
+ templates[format] = Mailer::Template.new(template)
77
77
  end
78
78
  templates
79
79
  end
@@ -83,7 +83,7 @@ module Hanami
83
83
  # @api private
84
84
  # @since 0.1.0
85
85
  def _find(lookup = search_path)
86
- Dir.glob( "#{ [root, lookup, template_name].join(separator) }.#{ format }.#{ engines }" )
86
+ Dir.glob("#{[root, lookup, template_name].join(separator)}.#{format}.#{engines}")
87
87
  end
88
88
 
89
89
  # @api private
@@ -1,6 +1,6 @@
1
1
  module Hanami
2
2
  module Mailer
3
3
  # @since 0.1.0
4
- VERSION = '0.2.0'.freeze
4
+ VERSION = '0.3.0'.freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2016-01-22 00:00:00.000000000 Z
13
+ date: 2016-07-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hanami-utils
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '0.7'
21
+ version: '0.8'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '0.7'
28
+ version: '0.8'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: tilt
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -80,14 +80,14 @@ dependencies:
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '10.0'
83
+ version: '11'
84
84
  type: :development
85
85
  prerelease: false
86
86
  version_requirements: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '10.0'
90
+ version: '11'
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: minitest
93
93
  requirement: !ruby/object:Gem::Requirement
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: 2.0.0
138
+ version: 2.2.0
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - ">="
@@ -143,9 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  requirements: []
145
145
  rubyforge_project:
146
- rubygems_version: 2.5.1
146
+ rubygems_version: 2.6.4
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: Mail for Ruby applications.
150
150
  test_files: []
151
- has_rdoc: