hertz-email 1.1.1 → 2.0.1
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 +4 -4
- data/README.md +15 -14
- data/Rakefile +5 -3
- data/app/jobs/hertz/email/notification_delivery_job.rb +18 -0
- data/app/mailers/hertz/email/notification_mailer.rb +36 -0
- data/lib/generators/hertz/email/install_generator.rb +13 -0
- data/lib/generators/hertz/{courier/email → email}/templates/initializer.rb +1 -1
- data/lib/hertz/email.rb +26 -0
- data/lib/hertz/email/engine.rb +9 -0
- data/lib/hertz/email/version.rb +7 -0
- metadata +12 -12
- data/app/jobs/hertz/courier/email/notification_delivery_job.rb +0 -20
- data/app/mailers/hertz/courier/email/notification_mailer.rb +0 -38
- data/lib/generators/hertz/courier/email/install_generator.rb +0 -15
- data/lib/hertz/courier/email.rb +0 -28
- data/lib/hertz/courier/email/engine.rb +0 -11
- data/lib/hertz/courier/email/version.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1159dc08d8bfa53e8bf76129ea31c31b068c33e608e0c999da6ef467c08f6025
|
4
|
+
data.tar.gz: 1cca543ad0098c75e3a797d303a981886abaad4c3fdcca2070ad4485f1be7390
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62cf5994a1a89ddb28aeb72d894164ccd318f5eeeca245bf4ded4de552414348404da6d337a0f75997c665695678bb20d349e3c66d41855fa30f2905ef43bc27
|
7
|
+
data.tar.gz: 12992bb11c91405862d1a51a0761554eefc8345c9dfe0eb8305feb726308491fe5826e2618018ac637511d6e505c745bf39d7b7433e942b6f690383e4234cb4b
|
data/README.md
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
# Hertz::
|
1
|
+
# Hertz::Email
|
2
2
|
|
3
3
|
[](https://travis-ci.org/aldesantis/hertz-email)
|
4
|
-
[](https://gemnasium.com/github.com/aldesantis/hertz-email)
|
5
4
|
[](https://coveralls.io/github/aldesantis/hertz-email?branch=master)
|
6
5
|
[](https://codeclimate.com/github/aldesantis/hertz-email/maintainability)
|
7
6
|
|
8
|
-
This is a [Hertz](https://github.com/
|
9
|
-
ActionMailer.
|
7
|
+
This is a [Hertz](https://github.com/aldesantis/hertz) courier for sending email notifications to
|
8
|
+
your users through ActionMailer.
|
10
9
|
|
11
10
|
## Installation
|
12
11
|
|
@@ -31,11 +30,11 @@ $ gem install hertz-email
|
|
31
30
|
Then, run the installer generator:
|
32
31
|
|
33
32
|
```console
|
34
|
-
$ rails g hertz:
|
33
|
+
$ rails g hertz:email:install
|
35
34
|
```
|
36
35
|
|
37
|
-
You will also need to expose the `hertz_email` method in your receiver class. This can be either a
|
38
|
-
array of emails:
|
36
|
+
You will also need to expose the `hertz_email` method in your receiver class. This can be either a
|
37
|
+
single email or an array of emails:
|
39
38
|
|
40
39
|
```ruby
|
41
40
|
class User < ActiveRecord::Base
|
@@ -47,9 +46,9 @@ class User < ActiveRecord::Base
|
|
47
46
|
end
|
48
47
|
```
|
49
48
|
|
50
|
-
If `#hertz_email` returns an empty value (i.e. `false`, `nil`, an empty string or an empty array) at
|
51
|
-
executed, the notification will not be delivered. This allows you to
|
52
|
-
for a user:
|
49
|
+
If `#hertz_email` returns an empty value (i.e. `false`, `nil`, an empty string or an empty array) at
|
50
|
+
the time the job is executed, the notification will not be delivered. This allows you to
|
51
|
+
programmatically enable/disable email notifications for a user:
|
53
52
|
|
54
53
|
```ruby
|
55
54
|
class User
|
@@ -93,7 +92,8 @@ class CommentNotification < Hertz::Notification
|
|
93
92
|
end
|
94
93
|
```
|
95
94
|
|
96
|
-
You may also pass more options to the `#mail` method of the mailer by defining a `#email_options`
|
95
|
+
You may also pass more options to the `#mail` method of the mailer by defining a `#email_options`
|
96
|
+
method:
|
97
97
|
|
98
98
|
```ruby
|
99
99
|
class CommentNotification < Hertz::Notification
|
@@ -106,8 +106,9 @@ class CommentNotification < Hertz::Notification
|
|
106
106
|
end
|
107
107
|
```
|
108
108
|
|
109
|
-
Finally, you should create a template for every notification you send by email. For
|
110
|
-
template at
|
109
|
+
Finally, you should create a template for every notification you send by email. For
|
110
|
+
`CommentNotification` you'd create a template at
|
111
|
+
`app/views/hertz/email/notification_mailer/comment_notification.html.erb`:
|
111
112
|
|
112
113
|
```erb
|
113
114
|
<p>Hey <%= @notification.receiver.hertz_email %>,</p>
|
@@ -121,7 +122,7 @@ to prevent double deliveries.
|
|
121
122
|
|
122
123
|
## Contributing
|
123
124
|
|
124
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
125
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/aldesantis/hertz-email.
|
125
126
|
|
126
127
|
## License
|
127
128
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hertz
|
4
|
+
module Email
|
5
|
+
class NotificationDeliveryJob < ActiveJob::Base
|
6
|
+
queue_as :default
|
7
|
+
|
8
|
+
def perform(notification)
|
9
|
+
return unless notification.receiver.hertz_email.present?
|
10
|
+
return if notification.delivered_with?(:email)
|
11
|
+
|
12
|
+
Hertz::Email::NotificationMailer.notification_email(notification).deliver_now
|
13
|
+
|
14
|
+
notification.mark_delivered_with(:email)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hertz
|
4
|
+
module Email
|
5
|
+
class NotificationMailer < Hertz::Email.base_mailer
|
6
|
+
def notification_email(notification)
|
7
|
+
@notification = notification
|
8
|
+
mail email_options_for(notification)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def email_options_for(notification)
|
14
|
+
options = {
|
15
|
+
to: notification.receiver.hertz_email,
|
16
|
+
subject: notification.email_subject,
|
17
|
+
template_name: view_for(notification)
|
18
|
+
}
|
19
|
+
|
20
|
+
if notification.respond_to?(:email_options)
|
21
|
+
options = options.merge(notification.email_options)
|
22
|
+
end
|
23
|
+
|
24
|
+
options
|
25
|
+
end
|
26
|
+
|
27
|
+
def view_for(notification)
|
28
|
+
if notification.respond_to?(:email_template)
|
29
|
+
notification.email_template
|
30
|
+
else
|
31
|
+
notification.class.to_s.underscore
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hertz
|
4
|
+
module Email
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
def copy_initializer_file
|
9
|
+
copy_file 'initializer.rb', 'config/initializers/hertz_email.rb'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/hertz/email.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hertz'
|
4
|
+
|
5
|
+
require 'hertz/email/engine'
|
6
|
+
require 'hertz/email/version'
|
7
|
+
|
8
|
+
module Hertz
|
9
|
+
module Email
|
10
|
+
class << self
|
11
|
+
mattr_writer :base_mailer
|
12
|
+
|
13
|
+
def base_mailer
|
14
|
+
(@base_mailer || '::ApplicationMailer').constantize
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure
|
18
|
+
yield(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def deliver_notification(notification)
|
22
|
+
Hertz::Email::NotificationDeliveryJob.perform_later(notification)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hertz-email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Desantis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hertz
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -194,13 +194,13 @@ files:
|
|
194
194
|
- MIT-LICENSE
|
195
195
|
- README.md
|
196
196
|
- Rakefile
|
197
|
-
- app/jobs/hertz/
|
198
|
-
- app/mailers/hertz/
|
199
|
-
- lib/generators/hertz/
|
200
|
-
- lib/generators/hertz/
|
201
|
-
- lib/hertz/
|
202
|
-
- lib/hertz/
|
203
|
-
- lib/hertz/
|
197
|
+
- app/jobs/hertz/email/notification_delivery_job.rb
|
198
|
+
- app/mailers/hertz/email/notification_mailer.rb
|
199
|
+
- lib/generators/hertz/email/install_generator.rb
|
200
|
+
- lib/generators/hertz/email/templates/initializer.rb
|
201
|
+
- lib/hertz/email.rb
|
202
|
+
- lib/hertz/email/engine.rb
|
203
|
+
- lib/hertz/email/version.rb
|
204
204
|
homepage: https://github.com/alessandro1997/hertz-email
|
205
205
|
licenses:
|
206
206
|
- MIT
|
@@ -221,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
221
|
version: '0'
|
222
222
|
requirements: []
|
223
223
|
rubyforge_project:
|
224
|
-
rubygems_version: 2.7.
|
224
|
+
rubygems_version: 2.7.7
|
225
225
|
signing_key:
|
226
226
|
specification_version: 4
|
227
227
|
summary: An ActionMailer courier for Hertz.
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Hertz
|
4
|
-
module Courier
|
5
|
-
module Email
|
6
|
-
class NotificationDeliveryJob < ActiveJob::Base
|
7
|
-
queue_as :default
|
8
|
-
|
9
|
-
def perform(notification)
|
10
|
-
return unless notification.receiver.hertz_email.present?
|
11
|
-
return if notification.delivered_with?(:email)
|
12
|
-
|
13
|
-
Hertz::Courier::Email::NotificationMailer.notification_email(notification).deliver_now
|
14
|
-
|
15
|
-
notification.mark_delivered_with(:email)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Hertz
|
4
|
-
module Courier
|
5
|
-
module Email
|
6
|
-
class NotificationMailer < Hertz::Courier::Email.base_mailer
|
7
|
-
def notification_email(notification)
|
8
|
-
@notification = notification
|
9
|
-
mail email_options_for(notification)
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def email_options_for(notification)
|
15
|
-
options = {
|
16
|
-
to: notification.receiver.hertz_email,
|
17
|
-
subject: notification.email_subject,
|
18
|
-
template_name: view_for(notification)
|
19
|
-
}
|
20
|
-
|
21
|
-
if notification.respond_to?(:email_options)
|
22
|
-
options = options.merge(notification.email_options)
|
23
|
-
end
|
24
|
-
|
25
|
-
options
|
26
|
-
end
|
27
|
-
|
28
|
-
def view_for(notification)
|
29
|
-
if notification.respond_to?(:email_template)
|
30
|
-
notification.email_template
|
31
|
-
else
|
32
|
-
notification.class.to_s.underscore
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Hertz
|
4
|
-
module Courier
|
5
|
-
module Email
|
6
|
-
class InstallGenerator < Rails::Generators::Base
|
7
|
-
source_root File.expand_path('../templates', __FILE__)
|
8
|
-
|
9
|
-
def copy_initializer_file
|
10
|
-
copy_file 'initializer.rb', 'config/initializers/hertz_email.rb'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/lib/hertz/courier/email.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'hertz'
|
4
|
-
|
5
|
-
require 'hertz/courier/email/engine'
|
6
|
-
require 'hertz/courier/email/version'
|
7
|
-
|
8
|
-
module Hertz
|
9
|
-
module Courier
|
10
|
-
module Email
|
11
|
-
class << self
|
12
|
-
mattr_writer :base_mailer
|
13
|
-
|
14
|
-
def base_mailer
|
15
|
-
(@base_mailer || '::ApplicationMailer').constantize
|
16
|
-
end
|
17
|
-
|
18
|
-
def configure
|
19
|
-
yield(self)
|
20
|
-
end
|
21
|
-
|
22
|
-
def deliver_notification(notification)
|
23
|
-
Hertz::Courier::Email::NotificationDeliveryJob.perform_later(notification)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|