caffeinate 2.0.5 → 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: 8d84c243657ac1177c4f95941325ae508cd67e9a4dd1d27a7f8eb070d641ee49
4
- data.tar.gz: c3541dc68d6611e673e235d9dcba55c584a1d854f1c0e38f3e379e391e88b5e1
3
+ metadata.gz: 6ee66cd0cefbff81f194970176755cde5fe49ccc8acd9307f3081bc13f71bd2f
4
+ data.tar.gz: 25380078f2edd4c8ccb7fdd4adc5903a783ce1f123ea59981def0bf5ee08698c
5
5
  SHA512:
6
- metadata.gz: 1bdda981dbdec2d7b655def0cba92d475e176f22577878e4dec8f50cc48b0668bdee23d53eba0eabe800e3bb92b43b5f93493a81be744b5336e5217ff9046e4c
7
- data.tar.gz: bbf2c4f17b7cee49956e7bf287497bffd653fde9920d343d75daae7c3b3a37c4ad2f2693c413b74ce9684628e0490b277b4b3b6d94feceac00c4afee9a7c6127
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
 
@@ -28,6 +28,10 @@ No! Not at all!
28
28
 
29
29
  There's not a lot of activity here because it's stable and working! I am more than happy to entertain new features.
30
30
 
31
+ ## Oh my gosh, a web UI!
32
+
33
+ See https://github.com/joshmn/caffeinate-webui for an accompanying lightweight UI for simple administrative tasks and overview.
34
+
31
35
  ## Do you suffer from ActionMailer tragedies?
32
36
 
33
37
  If you have _anything_ like this is your codebase, **you need Caffeinate**:
@@ -19,11 +19,11 @@ module Caffeinate
19
19
  private
20
20
 
21
21
  def caffeinate_subscribe_url(**options)
22
- Caffeinate::UrlHelpers.caffeinate_subscribe_url(@campaign_subscription, options)
22
+ Caffeinate::UrlHelpers.caffeinate_subscribe_url(@campaign_subscription, **options)
23
23
  end
24
24
 
25
25
  def caffeinate_unsubscribe_url(**options)
26
- Caffeinate::UrlHelpers.caffeinate_unsubscribe_url(@campaign_subscription, options)
26
+ Caffeinate::UrlHelpers.caffeinate_unsubscribe_url(@campaign_subscription, **options)
27
27
  end
28
28
 
29
29
  def find_campaign_subscription!
@@ -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
@@ -9,6 +9,7 @@ require 'caffeinate/dripper/drip'
9
9
  require 'caffeinate/dripper/inferences'
10
10
  require 'caffeinate/dripper/perform'
11
11
  require 'caffeinate/dripper/periodical'
12
+ require 'caffeinate/dripper/rescuable'
12
13
  require 'caffeinate/dripper/subscriber'
13
14
 
14
15
  module Caffeinate
@@ -24,6 +25,7 @@ module Caffeinate
24
25
  include Inferences
25
26
  include Perform
26
27
  include Periodical
28
+ include Rescuable
27
29
  include Subscriber
28
30
  end
29
31
  end
@@ -19,6 +19,7 @@ module Caffeinate
19
19
  else
20
20
  mailing.mailer_class.constantize.send(mailing.mailer_action, mailing)
21
21
  end
22
+
22
23
  message.caffeinate_mailing = mailing
23
24
  if ::Caffeinate.config.deliver_later?
24
25
  message.deliver_later
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Caffeinate
4
+ module Dripper
5
+ module Rescuable
6
+ def self.included(klass)
7
+ klass.include ::ActiveSupport::Rescuable
8
+ klass.extend ClassMethods
9
+ end
10
+
11
+ module ClassMethods
12
+ def deliver!(mailing)
13
+ begin
14
+ super
15
+ rescue Exception => exception
16
+ if self.rescue_with_handler(exception, object: mailing)
17
+ return
18
+ end
19
+ raise
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Caffeinate
4
- VERSION = '2.0.5'
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.0.5
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Brody
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-11 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
@@ -179,6 +180,7 @@ files:
179
180
  - lib/caffeinate/dripper/inferences.rb
180
181
  - lib/caffeinate/dripper/perform.rb
181
182
  - lib/caffeinate/dripper/periodical.rb
183
+ - lib/caffeinate/dripper/rescuable.rb
182
184
  - lib/caffeinate/dripper/subscriber.rb
183
185
  - lib/caffeinate/dripper_collection.rb
184
186
  - lib/caffeinate/engine.rb
@@ -200,7 +202,7 @@ homepage: https://github.com/joshmn/caffeinate
200
202
  licenses:
201
203
  - MIT
202
204
  metadata: {}
203
- post_install_message:
205
+ post_install_message:
204
206
  rdoc_options: []
205
207
  require_paths:
206
208
  - lib
@@ -216,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
218
  version: '0'
217
219
  requirements: []
218
220
  rubygems_version: 3.1.4
219
- signing_key:
221
+ signing_key:
220
222
  specification_version: 4
221
223
  summary: Create, manage, and send scheduled email sequences and drip campaigns from
222
224
  your Rails app.