bundle_notification 0.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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bundle_notification.gemspec +44 -0
- data/circle.yml +6 -0
- data/lib/bundle_notification/deliver.rb +38 -0
- data/lib/bundle_notification/mailer_helper.rb +22 -0
- data/lib/bundle_notification/snippet.rb +12 -0
- data/lib/bundle_notification/snippet_message.rb +22 -0
- data/lib/bundle_notification/version.rb +4 -0
- data/lib/bundle_notification.rb +7 -0
- metadata +208 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b046884fa40a09e53b7060881fc04a217669b1be
|
4
|
+
data.tar.gz: 493318dedbfa7f20d945e08c4c89a5050086fc66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b70c086cd7c621ee7a28537664f4abc61740200e1281b08265ff9e242969b7dedb5a9050239b4f35381d2e78098388bc12a204f4bf35a05ce87e23d7195c6243
|
7
|
+
data.tar.gz: 4ae21ba08bab367778aca463f57655e2d3e403d9b741aac6c5fb60500fadebe565682b4959e4a674f31794b63decd9243b636a1b8b64f483976b095b18274524
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.4
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Guilherme Goettems Schneider
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# BundleNotification
|
2
|
+
|
3
|
+
BundleNotification bundles many ActionMailer messages for the same recipient into a single email
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'bundle_notification'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install bundle_notification
|
20
|
+
|
21
|
+
|
22
|
+
Create bundle_notification_snippets table:
|
23
|
+
|
24
|
+
$ rails g migration CreateBundleNotificationSnippets mailer_class:string:index recipient:string data:text sent_at:datetime created_at:datetime
|
25
|
+
$ rake db:migrate
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
1. Include `BundleNotification::MailerHelper` to a mailer class.
|
30
|
+
2. Create any method you want and call `snippet` in the end passing the recipient email and any extra data you want.
|
31
|
+
3. Implement `bundle_notify` method which receives a recipient_email and an array of data
|
32
|
+
4. Call your method implemented in step 2 chained with `deliver_later` as you would do with a normal mailer method.
|
33
|
+
5. Call `deliver_unsent_snippets` for your mailer
|
34
|
+
|
35
|
+
Example:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class MyMailer < ActionMailer::Base
|
39
|
+
include BundleNotification::MailerHelper #1
|
40
|
+
|
41
|
+
def message(recipient_email, snippet_data)
|
42
|
+
snippet(recipient_email, snippet_data) #2
|
43
|
+
end
|
44
|
+
|
45
|
+
def bundle_notify(recipient_email, snippets_data) #3
|
46
|
+
@snippets_data = snippets_data
|
47
|
+
mail(to: recipient_email)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
MyMailer.message('recipient_1@example.com', 'message 1').deliver_later #4
|
52
|
+
MyMailer.message('recipient_1@example.com', 'message 2').deliver_later
|
53
|
+
MyMailer.message('recipient_2@example.com', 'message 3').deliver_later
|
54
|
+
|
55
|
+
MyMailer.deliver_unsent_snippets #5
|
56
|
+
```
|
57
|
+
|
58
|
+
This will send 2 emails: One to <recipient_1@example.com> with `['message 1', 'message 2']` and another to <recipient_2@example.com> with `['message 3']`
|
59
|
+
|
60
|
+
## Development
|
61
|
+
|
62
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
63
|
+
|
64
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ad2games/bundle_notification.
|
69
|
+
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
74
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bundle_notification"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'bundle_notification/version'
|
6
|
+
|
7
|
+
# rubocop:disable Metrics/BlockLength
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'bundle_notification'
|
10
|
+
spec.version = BundleNotification::VERSION
|
11
|
+
spec.authors = ['ad2games GmbH']
|
12
|
+
spec.email = ['developers@ad2games.com']
|
13
|
+
|
14
|
+
spec.summary = 'Bundle ActionMailer notifications'
|
15
|
+
spec.description = 'Bundle many ActionMailer messages for the same recipient into a single email'
|
16
|
+
spec.homepage = 'http://ad2games.com'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
else
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
23
|
+
'public gem pushes.'
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
|
+
spec.add_development_dependency 'actionmailer', '>= 4.0', '< 5.2'
|
37
|
+
spec.add_development_dependency 'sqlite3'
|
38
|
+
spec.add_development_dependency 'factory_girl'
|
39
|
+
spec.add_development_dependency 'simplecov'
|
40
|
+
|
41
|
+
spec.add_dependency 'activerecord', '>= 4.0', '< 5.2'
|
42
|
+
spec.add_dependency 'activesupport', '>= 4.0', '< 5.2'
|
43
|
+
end
|
44
|
+
# rubocop:enable Metrics/BlockLength
|
data/circle.yml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'active_support/time'
|
3
|
+
require 'bundle_notification/snippet'
|
4
|
+
|
5
|
+
module BundleNotification
|
6
|
+
class Deliver
|
7
|
+
attr_reader :mailer_class
|
8
|
+
|
9
|
+
def initialize(mailer_class)
|
10
|
+
@mailer_class = mailer_class
|
11
|
+
end
|
12
|
+
|
13
|
+
def deliver_unsent_snippets
|
14
|
+
Snippet.transaction do
|
15
|
+
return if unsent_snippets.empty?
|
16
|
+
unsent_snippets.group_by(&:recipient).each do |recipient, snippets|
|
17
|
+
bundle_notify(recipient, snippets.map(&:data)).deliver_later
|
18
|
+
end
|
19
|
+
mark_snippets_sent
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def bundle_notify(bundle_data, snippets_data)
|
26
|
+
mailer_class.constantize.bundle_notify(bundle_data, snippets_data)
|
27
|
+
end
|
28
|
+
|
29
|
+
def unsent_snippets
|
30
|
+
@unsent_snippets ||= Snippet.unsent_for(mailer_class).order(:created_at, :id).lock.to_a
|
31
|
+
end
|
32
|
+
|
33
|
+
def mark_snippets_sent
|
34
|
+
Snippet.where(id: unsent_snippets).update_all(sent_at: (Time.zone || Time).now)
|
35
|
+
@unsent_snippets = nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'active_support/concern'
|
3
|
+
require 'bundle_notification/deliver'
|
4
|
+
require 'bundle_notification/snippet_message'
|
5
|
+
|
6
|
+
module BundleNotification
|
7
|
+
module MailerHelper
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
class_methods do
|
11
|
+
def deliver_unsent_snippets
|
12
|
+
Deliver.new(to_s).deliver_unsent_snippets
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def snippet(recipient, snippet_data)
|
17
|
+
# SnippetMessage will replace Mail::Message of ActionMailer::MessageDelivery
|
18
|
+
@_mail_was_called = true
|
19
|
+
@_message = SnippetMessage.new(self.class.to_s, recipient, snippet_data)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
module BundleNotification
|
5
|
+
class Snippet < ActiveRecord::Base
|
6
|
+
self.table_name = 'bundle_notification_snippets'
|
7
|
+
|
8
|
+
serialize :data
|
9
|
+
|
10
|
+
scope :unsent_for, ->(mailer_class) { where(mailer_class: mailer_class, sent_at: nil) }
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'bundle_notification/snippet'
|
3
|
+
|
4
|
+
module BundleNotification
|
5
|
+
class SnippetMessage
|
6
|
+
attr_reader :mailer_class, :recipient, :snippet_data
|
7
|
+
|
8
|
+
def initialize(mailer_class, recipient, snippet_data)
|
9
|
+
@mailer_class = mailer_class
|
10
|
+
@recipient = recipient
|
11
|
+
@snippet_data = snippet_data
|
12
|
+
end
|
13
|
+
|
14
|
+
def deliver
|
15
|
+
Snippet.create!(
|
16
|
+
mailer_class: mailer_class,
|
17
|
+
recipient: recipient,
|
18
|
+
data: snippet_data
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bundle_notification
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ad2games GmbH
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: actionmailer
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '5.2'
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '4.0'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '5.2'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: sqlite3
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: factory_girl
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: simplecov
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: activerecord
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '4.0'
|
124
|
+
- - "<"
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '5.2'
|
127
|
+
type: :runtime
|
128
|
+
prerelease: false
|
129
|
+
version_requirements: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '4.0'
|
134
|
+
- - "<"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '5.2'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: activesupport
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '4.0'
|
144
|
+
- - "<"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '5.2'
|
147
|
+
type: :runtime
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '4.0'
|
154
|
+
- - "<"
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '5.2'
|
157
|
+
description: Bundle many ActionMailer messages for the same recipient into a single
|
158
|
+
email
|
159
|
+
email:
|
160
|
+
- developers@ad2games.com
|
161
|
+
executables: []
|
162
|
+
extensions: []
|
163
|
+
extra_rdoc_files: []
|
164
|
+
files:
|
165
|
+
- ".gitignore"
|
166
|
+
- ".rspec"
|
167
|
+
- ".ruby-version"
|
168
|
+
- ".travis.yml"
|
169
|
+
- Gemfile
|
170
|
+
- LICENSE.txt
|
171
|
+
- README.md
|
172
|
+
- Rakefile
|
173
|
+
- bin/console
|
174
|
+
- bin/setup
|
175
|
+
- bundle_notification.gemspec
|
176
|
+
- circle.yml
|
177
|
+
- lib/bundle_notification.rb
|
178
|
+
- lib/bundle_notification/deliver.rb
|
179
|
+
- lib/bundle_notification/mailer_helper.rb
|
180
|
+
- lib/bundle_notification/snippet.rb
|
181
|
+
- lib/bundle_notification/snippet_message.rb
|
182
|
+
- lib/bundle_notification/version.rb
|
183
|
+
homepage: http://ad2games.com
|
184
|
+
licenses:
|
185
|
+
- MIT
|
186
|
+
metadata:
|
187
|
+
allowed_push_host: https://rubygems.org
|
188
|
+
post_install_message:
|
189
|
+
rdoc_options: []
|
190
|
+
require_paths:
|
191
|
+
- lib
|
192
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
requirements: []
|
203
|
+
rubyforge_project:
|
204
|
+
rubygems_version: 2.5.2
|
205
|
+
signing_key:
|
206
|
+
specification_version: 4
|
207
|
+
summary: Bundle ActionMailer notifications
|
208
|
+
test_files: []
|