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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43158448cc5f38f5297de7897bbca720660ed53a3b9b54e48a9575d8972f967c
4
- data.tar.gz: c41d7b93ecb80fee73ca72dec24066b86f5c598df851cc367118f18d84d9e42a
3
+ metadata.gz: 1159dc08d8bfa53e8bf76129ea31c31b068c33e608e0c999da6ef467c08f6025
4
+ data.tar.gz: 1cca543ad0098c75e3a797d303a981886abaad4c3fdcca2070ad4485f1be7390
5
5
  SHA512:
6
- metadata.gz: 938b7a352b89458aa5ac3345dae591aa7cbfc3aa3751f250d6a8e23f1ce0f505bdebd79da1f03e1a900434ad3b8db82799b535d943eb349c80047265c55874aa
7
- data.tar.gz: cd13ccb6e7f76369bc5908f0609878fe0a2ef4d50203397690582210ce898a4f55f467969b9abeac6280ae21c73970f706f7fa96ed4c0a3cd0ee59a66f018de2
6
+ metadata.gz: 62cf5994a1a89ddb28aeb72d894164ccd318f5eeeca245bf4ded4de552414348404da6d337a0f75997c665695678bb20d349e3c66d41855fa30f2905ef43bc27
7
+ data.tar.gz: 12992bb11c91405862d1a51a0761554eefc8345c9dfe0eb8305feb726308491fe5826e2618018ac637511d6e505c745bf39d7b7433e942b6f690383e4234cb4b
data/README.md CHANGED
@@ -1,12 +1,11 @@
1
- # Hertz::Courier::Email
1
+ # Hertz::Email
2
2
 
3
3
  [![Build Status](https://travis-ci.org/aldesantis/hertz-email.svg?branch=master)](https://travis-ci.org/aldesantis/hertz-email)
4
- [![Dependency Status](https://gemnasium.com/badges/github.com/aldesantis/hertz-email.svg)](https://gemnasium.com/github.com/aldesantis/hertz-email)
5
4
  [![Coverage Status](https://coveralls.io/repos/github/aldesantis/hertz-email/badge.svg?branch=master)](https://coveralls.io/github/aldesantis/hertz-email?branch=master)
6
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/c71c1821b56b288ea71a/maintainability)](https://codeclimate.com/github/aldesantis/hertz-email/maintainability)
7
6
 
8
- This is a [Hertz](https://github.com/alessandro1997/hertz) courier for sending email notifications to your users through
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:courier:email:install
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 single email or an
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 the time the job is
51
- executed, the notification will not be delivered. This allows you to programmatically enable/disable email notifications
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` method:
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 `CommentNotification` you'd create a
110
- template at `app/views/hertz/courier/email/notification_mailer/comment_notification.html.erb`:
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/alessandro1997/hertz-email.
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
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Hertz::Courier::Email.configure do |config|
3
+ Hertz::Email.configure do |config|
4
4
  # Your base mailer class, for delivering notifications by email.
5
5
  config.base_mailer = '::ApplicationMailer'
6
6
  end
@@ -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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hertz
4
+ module Email
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace Hertz::Email
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hertz
4
+ module Email
5
+ VERSION = '2.0.1'
6
+ end
7
+ 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: 1.1.1
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-02-14 00:00:00.000000000 Z
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: '1.0'
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: '1.0'
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/courier/email/notification_delivery_job.rb
198
- - app/mailers/hertz/courier/email/notification_mailer.rb
199
- - lib/generators/hertz/courier/email/install_generator.rb
200
- - lib/generators/hertz/courier/email/templates/initializer.rb
201
- - lib/hertz/courier/email.rb
202
- - lib/hertz/courier/email/engine.rb
203
- - lib/hertz/courier/email/version.rb
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.5
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
@@ -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
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Hertz
4
- module Courier
5
- module Email
6
- class Engine < ::Rails::Engine
7
- isolate_namespace Hertz::Courier::Email
8
- end
9
- end
10
- end
11
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Hertz
4
- module Courier
5
- module Email
6
- VERSION = '1.1.1'
7
- end
8
- end
9
- end