active_delivery 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/.travis.yml +10 -5
- data/CHANGELOG.md +4 -0
- data/README.md +3 -1
- data/active_delivery.gemspec +3 -1
- data/lib/active_delivery/action_mailer/parameterized.rb +86 -0
- data/lib/active_delivery/lines/mailer.rb +4 -0
- data/lib/active_delivery/testing/rspec.rb +2 -2
- data/lib/active_delivery/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cedb82b0e98de0ae19e5035da765b9ccdac620a1d06a278b078bd5154931f47
|
4
|
+
data.tar.gz: 29f91381de756f4b4ae8d67a4cc86e060fab9401c2f47926b4e9a3ad396301c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b0c9deef2835eddf0513893908c3a97320e4b883b3a3b96dde6026a7c96b4eb3330ec58ff6d294c3b319a3af09192d6f317af511a7ba171343847146898bad4
|
7
|
+
data.tar.gz: f13926f59dc414091d36b3a7b8fd238e1119fcc1a4da8b4c4070b0819b2c3015ff247d70bc663f653dcf85c4472bbd00069fb7a363fbf9488097eec9b9f22cc7
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,25 +1,30 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
|
-
|
4
|
-
- 2.5.1
|
3
|
+
cache: bundler
|
5
4
|
|
6
5
|
notifications:
|
7
6
|
email: false
|
8
7
|
|
8
|
+
before_install:
|
9
|
+
- gem update --system
|
10
|
+
- gem install bundler -v '< 2'
|
11
|
+
|
9
12
|
matrix:
|
10
13
|
fast_finish: true
|
11
14
|
include:
|
12
15
|
- rvm: ruby-head
|
13
16
|
gemfile: gemfiles/railsmaster.gemfile
|
14
|
-
- rvm: 2.5.
|
17
|
+
- rvm: 2.5.3
|
18
|
+
gemfile: Gemfile
|
19
|
+
- rvm: 2.6.0
|
15
20
|
gemfile: Gemfile
|
16
|
-
- rvm: 2.5.
|
21
|
+
- rvm: 2.5.3
|
17
22
|
gemfile: Gemfile
|
18
23
|
env:
|
19
24
|
- NO_RAILS=1
|
20
25
|
- rvm: 2.4.3
|
21
26
|
gemfile: Gemfile
|
22
|
-
- rvm: 2.3
|
27
|
+
- rvm: 2.4.3
|
23
28
|
gemfile: gemfiles/rails42.gemfile
|
24
29
|
allow_failures:
|
25
30
|
- rvm: ruby-head
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -5,11 +5,13 @@
|
|
5
5
|
|
6
6
|
Framework providing an entry point (single _interface_) for all types of notifications: mailers, push notifications, whatever you want.
|
7
7
|
|
8
|
+
📖 Read the introduction post: ["Crafting user notifications in Rails with Active Delivery"](https://dev.to/evilmartians/crafting-user-notifications-in-rails-with-active-delivery-5cn6")
|
9
|
+
|
8
10
|
<a href="https://evilmartians.com/?utm_source=action_policy">
|
9
11
|
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
|
10
12
|
|
11
13
|
Requirements:
|
12
|
-
- Ruby ~> 2.
|
14
|
+
- Ruby ~> 2.4
|
13
15
|
|
14
16
|
**NOTE**: although most of the examples in this readme are Rails-specific, this gem could be used without Rails/ActiveSupport.
|
15
17
|
|
data/active_delivery.gemspec
CHANGED
@@ -15,10 +15,12 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.homepage = "https://github.com/palkan/active_delivery"
|
16
16
|
spec.license = "MIT"
|
17
17
|
|
18
|
+
spec.required_ruby_version = ">= 2.4"
|
19
|
+
|
18
20
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
21
|
spec.require_paths = ["lib"]
|
20
22
|
|
21
|
-
spec.add_development_dependency "bundler", "
|
23
|
+
spec.add_development_dependency "bundler", ">= 1.16"
|
22
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
25
|
spec.add_development_dependency "rspec", "~> 3.0"
|
24
26
|
spec.add_development_dependency "standard", "~> 0.0.12"
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionMailer
|
4
|
+
# See https://api.rubyonrails.org/classes/ActionMailer/Parameterized.html
|
5
|
+
module Parameterized
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
attr_accessor :params
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
# Provide the parameters to the mailer in order to use them in the instance methods and callbacks.
|
14
|
+
#
|
15
|
+
# InvitationsMailer.with(inviter: person_a, invitee: person_b).account_invitation.deliver_later
|
16
|
+
#
|
17
|
+
# See Parameterized documentation for full example.
|
18
|
+
def with(params)
|
19
|
+
ActionMailer::Parameterized::Mailer.new(self, params)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Mailer # :nodoc:
|
24
|
+
def initialize(mailer, params)
|
25
|
+
@mailer, @params = mailer, params
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def method_missing(method_name, *args)
|
31
|
+
if @mailer.action_methods.include?(method_name.to_s)
|
32
|
+
ActionMailer::Parameterized::MessageDelivery.new(@mailer, method_name, @params, *args)
|
33
|
+
else
|
34
|
+
super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def respond_to_missing?(method, include_all = false)
|
39
|
+
@mailer.respond_to?(method, include_all)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class MessageDelivery < ActionMailer::MessageDelivery # :nodoc:
|
44
|
+
def initialize(mailer_class, action, params, *args)
|
45
|
+
super(mailer_class, action, *args)
|
46
|
+
@params = params
|
47
|
+
end
|
48
|
+
|
49
|
+
def __getobj__ #:nodoc:
|
50
|
+
@obj ||= processed_mailer.message
|
51
|
+
end
|
52
|
+
|
53
|
+
def processed?
|
54
|
+
@processed_mailer || @obj
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def processed_mailer
|
60
|
+
@processed_mailer ||= @mailer.send(:new, nil, *@args).tap do |m|
|
61
|
+
m.params = @params
|
62
|
+
m.process @mail_method, *@args
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def enqueue_delivery(delivery_method, options = {})
|
67
|
+
if processed?
|
68
|
+
super
|
69
|
+
else
|
70
|
+
args = @mailer.name, @mail_method.to_s, delivery_method.to_s, @params, *@args
|
71
|
+
ActionMailer::Parameterized::DeliveryJob.set(options).perform_later(*args)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class DeliveryJob < ActionMailer::DeliveryJob # :nodoc:
|
77
|
+
def perform(mailer, mail_method, delivery_method, params, *args)
|
78
|
+
mailer.constantize.with(params).public_send(mail_method, *args).send(delivery_method)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
ActiveSupport.on_load(:action_mailer) do
|
85
|
+
include ActionMailer::Parameterized
|
86
|
+
end
|
@@ -93,7 +93,7 @@ module ActiveDelivery
|
|
93
93
|
msg << " :#{event} notification" if event
|
94
94
|
msg << " via #{delivery_class}#{sync_value ? " (sync)" : ""} with:"
|
95
95
|
msg << "\n - params: #{params_description(params)}" if params
|
96
|
-
msg << "\n - args: #{args.
|
96
|
+
msg << "\n - args: #{args.empty? ? "<none>" : args}"
|
97
97
|
msg << "\n#{message_expectation_modifier}, but"
|
98
98
|
|
99
99
|
if @unmatching_deliveries.any?
|
@@ -102,7 +102,7 @@ module ActiveDelivery
|
|
102
102
|
msg << "\n :#{event} via #{delivery.class}" \
|
103
103
|
"#{options[:sync] ? " (sync)" : ""}" \
|
104
104
|
" with:" \
|
105
|
-
"\n - params: #{delivery.params.
|
105
|
+
"\n - params: #{delivery.params.empty? ? "<none>" : delivery.params.to_s}" \
|
106
106
|
"\n - args: #{args}"
|
107
107
|
end
|
108
108
|
else
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_delivery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.16'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.16'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- gemfiles/rails42.gemfile
|
89
89
|
- gemfiles/railsmaster.gemfile
|
90
90
|
- lib/active_delivery.rb
|
91
|
+
- lib/active_delivery/action_mailer/parameterized.rb
|
91
92
|
- lib/active_delivery/base.rb
|
92
93
|
- lib/active_delivery/callbacks.rb
|
93
94
|
- lib/active_delivery/lines/base.rb
|
@@ -107,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
108
|
requirements:
|
108
109
|
- - ">="
|
109
110
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
111
|
+
version: '2.4'
|
111
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
113
|
requirements:
|
113
114
|
- - ">="
|