caffeinate 0.4.1 → 0.5.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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cac59a69d742f7948455f3f3b5787e33841664267eab72a2c6bc296735da5d1e
|
4
|
+
data.tar.gz: 826ca15444ba2242f99d8376d0f5a4aae9612846ee61ef53d1a4a53a879d0b54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d1cc9c295d50c77c5db6c5f22d585372b513396d54a9a37b05f40af405f8f4e32b1e0d42045a9e5b0e0c40fe592466a4d835a67dd71ad62bab55d24b7586d15
|
7
|
+
data.tar.gz: 0ca6801b63b8e50f73654dbc6a7f5e9c5063fd825699bd6698e4af4f6846ef23358ed0955cc2d0ed8d19e705124d0f25094c0980331dd90dd31121ab06c07f3e
|
@@ -17,9 +17,14 @@
|
|
17
17
|
# updated_at :datetime not null
|
18
18
|
#
|
19
19
|
module Caffeinate
|
20
|
+
# If a record tries to be `unsubscribed!` or `ended!` or `resubscribe!` and it's in a state that is not
|
21
|
+
# correct, raise this
|
22
|
+
class InvalidState < ::ActiveRecord::RecordInvalid; end
|
23
|
+
|
20
24
|
# CampaignSubscription associates an object and its optional user to a Campaign
|
21
25
|
# and its relevant Mailings.
|
22
26
|
class CampaignSubscription < ApplicationRecord
|
27
|
+
|
23
28
|
self.table_name = 'caffeinate_campaign_subscriptions'
|
24
29
|
|
25
30
|
has_many :caffeinate_mailings, class_name: 'Caffeinate::Mailing', foreign_key: :caffeinate_campaign_subscription_id, dependent: :destroy
|
@@ -66,23 +71,34 @@ module Caffeinate
|
|
66
71
|
|
67
72
|
# Updates `ended_at` and runs `on_complete` callbacks
|
68
73
|
def end!(reason = nil)
|
74
|
+
raise ::Caffeinate::InvalidState, "CampaignSubscription is already unsubscribed." if unsubscribed?
|
75
|
+
|
69
76
|
update!(ended_at: ::Caffeinate.config.time_now, ended_reason: reason)
|
70
77
|
|
71
|
-
caffeinate_campaign.to_dripper.run_callbacks(:
|
78
|
+
caffeinate_campaign.to_dripper.run_callbacks(:on_end, self)
|
79
|
+
true
|
72
80
|
end
|
73
81
|
|
74
82
|
# Updates `unsubscribed_at` and runs `on_subscribe` callbacks
|
75
83
|
def unsubscribe!(reason = nil)
|
84
|
+
raise ::Caffeinate::InvalidState, "CampaignSubscription is already ended." if ended?
|
85
|
+
|
76
86
|
update!(unsubscribed_at: ::Caffeinate.config.time_now, unsubscribe_reason: reason)
|
77
87
|
|
78
88
|
caffeinate_campaign.to_dripper.run_callbacks(:on_unsubscribe, self)
|
89
|
+
true
|
79
90
|
end
|
80
91
|
|
81
|
-
# Updates `unsubscribed_at` to nil and runs `on_subscribe` callbacks
|
82
|
-
|
92
|
+
# Updates `unsubscribed_at` to nil and runs `on_subscribe` callbacks.
|
93
|
+
# Use `force` to forcefully reset. Does not create the mailings.
|
94
|
+
def resubscribe!(force = false)
|
95
|
+
raise ::Caffeinate::InvalidState, "CampaignSubscription is already ended." if ended? && !force
|
96
|
+
raise ::Caffeinate::InvalidState, "CampaignSubscription is already unsubscribed." if unsubscribed? && !force
|
97
|
+
|
83
98
|
update!(unsubscribed_at: nil, resubscribed_at: ::Caffeinate.config.time_now)
|
84
99
|
|
85
100
|
caffeinate_campaign.to_dripper.run_callbacks(:on_resubscribe, self)
|
101
|
+
true
|
86
102
|
end
|
87
103
|
|
88
104
|
private
|
@@ -94,6 +110,7 @@ module Caffeinate
|
|
94
110
|
mailing.save!
|
95
111
|
end
|
96
112
|
caffeinate_campaign.to_dripper.run_callbacks(:on_subscribe, self)
|
113
|
+
true
|
97
114
|
end
|
98
115
|
|
99
116
|
def set_token!
|
@@ -40,18 +40,18 @@ module Caffeinate
|
|
40
40
|
|
41
41
|
# Callback before the mailings get processed.
|
42
42
|
#
|
43
|
-
#
|
43
|
+
# before_perform do |dripper|
|
44
44
|
# Slack.notify(:caffeinate, "Dripper is getting ready for mailing! #{dripper.caffeinate_campaign.name}!")
|
45
45
|
# end
|
46
46
|
#
|
47
47
|
# @yield Caffeinate::Dripper
|
48
|
-
def
|
49
|
-
|
48
|
+
def before_perform(&block)
|
49
|
+
before_perform_blocks << block
|
50
50
|
end
|
51
51
|
|
52
52
|
# :nodoc:
|
53
|
-
def
|
54
|
-
@
|
53
|
+
def before_perform_blocks
|
54
|
+
@before_perform_blocks ||= []
|
55
55
|
end
|
56
56
|
|
57
57
|
# Callback before the mailings get processed in a batch.
|
@@ -62,13 +62,13 @@ module Caffeinate
|
|
62
62
|
#
|
63
63
|
# @yield Caffeinate::Dripper
|
64
64
|
# @yield Caffeinate::Mailing [Array]
|
65
|
-
def
|
66
|
-
|
65
|
+
def on_perform(&block)
|
66
|
+
on_perform_blocks << block
|
67
67
|
end
|
68
68
|
|
69
69
|
# :nodoc:
|
70
|
-
def
|
71
|
-
@
|
70
|
+
def on_perform_blocks
|
71
|
+
@on_perform_blocks ||= []
|
72
72
|
end
|
73
73
|
|
74
74
|
# Callback after the all the mailings have been sent.
|
@@ -79,13 +79,13 @@ module Caffeinate
|
|
79
79
|
#
|
80
80
|
# @yield Caffeinate::Dripper
|
81
81
|
# @yield Caffeinate::Mailing [Array]
|
82
|
-
def
|
83
|
-
|
82
|
+
def after_perform(&block)
|
83
|
+
after_perform_blocks << block
|
84
84
|
end
|
85
85
|
|
86
86
|
# :nodoc:
|
87
|
-
def
|
88
|
-
@
|
87
|
+
def after_perform_blocks
|
88
|
+
@after_perform_blocks ||= []
|
89
89
|
end
|
90
90
|
|
91
91
|
# Callback before a Drip has called the mailer.
|
@@ -171,6 +171,23 @@ module Caffeinate
|
|
171
171
|
@on_unsubscribe_blocks ||= []
|
172
172
|
end
|
173
173
|
|
174
|
+
|
175
|
+
# Callback after a CampaignSubscriber has ended.
|
176
|
+
#
|
177
|
+
# on_end do |campaign_sub|
|
178
|
+
# Slack.notify(:caffeinate, "#{campaign_sub.id} has ended... sad day.")
|
179
|
+
# end
|
180
|
+
#
|
181
|
+
# @yield Caffeinate::CampaignSubscription
|
182
|
+
def on_end(&block)
|
183
|
+
on_end_blocks << block
|
184
|
+
end
|
185
|
+
|
186
|
+
# :nodoc:
|
187
|
+
def on_end_blocks
|
188
|
+
@on_end_blocks ||= []
|
189
|
+
end
|
190
|
+
|
174
191
|
# Callback after a `Caffeinate::Mailing` is skipped.
|
175
192
|
#
|
176
193
|
# on_skip do |campaign_subscription, mailing, message|
|
@@ -15,28 +15,20 @@ module Caffeinate
|
|
15
15
|
#
|
16
16
|
# @return nil
|
17
17
|
def perform!
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
.joins(:next_caffeinate_mailing)
|
30
|
-
.preload(*preloads)
|
31
|
-
.includes(*includes)
|
32
|
-
.in_batches(of: self.class.batch_size)
|
33
|
-
.each do |batch|
|
34
|
-
run_callbacks(:on_process, self, batch)
|
35
|
-
batch.each do |subscriber|
|
36
|
-
subscriber.next_caffeinate_mailing.process!
|
18
|
+
run_callbacks(:before_perform, self)
|
19
|
+
Caffeinate::Mailing
|
20
|
+
.upcoming
|
21
|
+
.unsent
|
22
|
+
.joins(:caffeinate_campaign_subscription)
|
23
|
+
.merge(Caffeinate::CampaignSubscription.active)
|
24
|
+
.in_batches(of: self.class.batch_size)
|
25
|
+
.each do |batch|
|
26
|
+
run_callbacks(:on_perform, self, batch)
|
27
|
+
batch.each do |mailing|
|
28
|
+
mailing.process!
|
37
29
|
end
|
38
30
|
end
|
39
|
-
run_callbacks(:
|
31
|
+
run_callbacks(:after_perform, self)
|
40
32
|
nil
|
41
33
|
end
|
42
34
|
|
data/lib/caffeinate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caffeinate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Brody
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|