caffeinate 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99e1c4493c6e9c0a024a789e5ee16383afe64fa73b6263ee2482dcace8038703
4
- data.tar.gz: 9d49f256a79051ad3264de0444843dd5dc5c4bf8cf74fd77021709728f9dc8b4
3
+ metadata.gz: 6ee66cd0cefbff81f194970176755cde5fe49ccc8acd9307f3081bc13f71bd2f
4
+ data.tar.gz: 25380078f2edd4c8ccb7fdd4adc5903a783ce1f123ea59981def0bf5ee08698c
5
5
  SHA512:
6
- metadata.gz: 76f7ed8231cfc694d020edc3432e064bed577aad92fbc7e0bd3e5bed9b9d93a10b3b7d5650fbd72a10911dff29484aa19dfdfa64c2971fb8b47f7d0ef8312402
7
- data.tar.gz: 668b441c7fda4930186e9bae3758c8d0d29eac861f0f2079dc3f17602fbefa5e96ec323508679c243f87272153fc89f3066c1fd5931e25fcbd2ff42ef856a6f0
6
+ metadata.gz: 5fe9f92105e1acf59ce7f931a75a3e5d7e7a7ed5a58ee19d1b9cd1ce661c3f86011e3e910576fdad058009a8a2b2e54ab1e99eb073f11ec5a4d6bd27a9c30f47
7
+ data.tar.gz: 397e39515c8d7bf8e7bfb1d794b0beb434bb916af1f4ac310a027c9a9f21fb8ef0a74abf99acc53f6f59e8efd6b32ac50239e75cb329241d5d3ca8cc3a876405
data/README.md CHANGED
@@ -20,7 +20,7 @@ Caffeinate is a drip email engine for managing, creating, and sending scheduled
20
20
 
21
21
  Caffeinate provides a simple DSL to create scheduled email sequences which can be used by ActionMailer without any additional configuration.
22
22
 
23
- There's a cool demo with all the things included at [caffeinate.email](https://caffeinate.email). You can view the [marketing site source code here](https://github.com/joshmn/caffeinate-marketing).
23
+ There's a cool demo app you can spin up [here](https://github.com/joshmn/caffeinate-marketing).
24
24
 
25
25
  ## Is this thing dead?
26
26
 
@@ -16,6 +16,7 @@
16
16
  # created_at :datetime not null
17
17
  # updated_at :datetime not null
18
18
  #
19
+
19
20
  module Caffeinate
20
21
  # If a record tries to be `unsubscribed!` or `ended!` or `resubscribe!` and it's in a state that is not
21
22
  # correct, raise this
@@ -59,6 +60,22 @@ module Caffeinate
59
60
 
60
61
  after_commit :on_complete, if: :completed?
61
62
 
63
+ # Add (new) drips to a `CampaignSubscriber`.
64
+ #
65
+ # Useful if you added new drips to a `Campaign` and have existing `CampaignSubscription`
66
+ # which you want to add them to.
67
+ #
68
+ # Pass `:created_at` if you want to offset `Mailing#send_at` time from the time the `CampaignSubscription`
69
+ # was originally created. That is to say that if you add a new drip for 5 days from now, the mailing will be sent
70
+ # 5 days from when the `CampaignSubscription` was created.
71
+ #
72
+ # Pass `:current` to offset from the current time (doesn't offset anything, actually)
73
+ def refuel!(offset: :created_at)
74
+ ::CampaignSubscriptions::RefuelService.new(self, offset: offset).call
75
+
76
+ true
77
+ end
78
+
62
79
  # Actually deliver and process the mail
63
80
  def deliver!(mailing)
64
81
  caffeinate_campaign.to_dripper.deliver!(mailing)
@@ -32,6 +32,14 @@ module Caffeinate
32
32
 
33
33
  after_touch :end_if_no_mailings!
34
34
 
35
+ def self.find_or_initialize_from_drip(campaign_subscription, drip)
36
+ find_or_initialize_by(
37
+ caffeinate_campaign_subscription: campaign_subscription,
38
+ mailer_class: drip.options[:mailer_class],
39
+ mailer_action: drip.action
40
+ )
41
+ end
42
+
35
43
  def initialize_dup(args)
36
44
  super
37
45
  self.send_at = nil
@@ -0,0 +1,33 @@
1
+ module CampaignSubscriptions
2
+ class RefuelService
3
+
4
+ def initialize(campaign_subscription, offset: :created_at)
5
+ raise ArgumentError, "must be either :current or :created_at" unless [:created_at, :current].include?(offset.to_sym)
6
+
7
+ @campaign_subscription = campaign_subscription
8
+ @campaign = @campaign_subscription.caffeinate_campaign
9
+ @offset = offset.to_sym
10
+ end
11
+
12
+ def call
13
+ mailings = []
14
+
15
+ @campaign.to_dripper.drips.each do |drip|
16
+ mailing = Caffeinate::Mailing.find_or_initialize_from_drip(@campaign_subscription, drip)
17
+ if mailing.new_record?
18
+ mailing.send_at = drip.send_at(@campaign_subscription)
19
+ if @offset == :created_at
20
+ mailing.send_at + (Caffeinate.config.now.call - @campaign_subscription.created_at)
21
+ elsif @offset == :current
22
+ # do nothing on purpose!
23
+ end
24
+
25
+ mailing.save!
26
+ mailings << mailing
27
+ end
28
+ end
29
+
30
+ mailings
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Caffeinate
4
- VERSION = '2.1.0'
4
+ VERSION = '2.2.0'
5
5
  end
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: 2.1.0
4
+ version: 2.2.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: 2023-01-14 00:00:00.000000000 Z
11
+ date: 2023-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -153,6 +153,7 @@ files:
153
153
  - app/models/caffeinate/campaign.rb
154
154
  - app/models/caffeinate/campaign_subscription.rb
155
155
  - app/models/caffeinate/mailing.rb
156
+ - app/services/campaign_subscriptions/refuel_service.rb
156
157
  - app/views/caffeinate/campaign_subscriptions/subscribe.html.erb
157
158
  - app/views/caffeinate/campaign_subscriptions/unsubscribe.html.erb
158
159
  - app/views/layouts/_caffeinate.html.erb