Module: Caffeinate::Dripper::Callbacks::ClassMethods
- Defined in:
- lib/caffeinate/dripper/callbacks.rb
Instance Method Summary collapse
-
#after_perform { ... } ⇒ Object
Callback after the all the mailings have been sent.
-
#after_perform_blocks ⇒ Object
:nodoc:.
-
#after_send { ... } ⇒ Object
Callback after a Mailing has been sent.
-
#after_send_blocks ⇒ Object
:nodoc:.
-
#before_drip { ... } ⇒ Object
Callback before a Drip has called the mailer.
-
#before_drip_blocks ⇒ Object
:nodoc:.
-
#before_perform { ... } ⇒ Object
Callback before the mailings get processed.
-
#before_perform_blocks ⇒ Object
:nodoc:.
-
#before_send { ... } ⇒ Object
Callback before a Mailing has been sent.
-
#before_send_blocks ⇒ Object
:nodoc:.
- #before_subscribe(&block) ⇒ Object
- #before_subscribe_blocks ⇒ Object
-
#callbacks_for(name) ⇒ Object
:nodoc:.
-
#on_complete { ... } ⇒ Object
Callback after a CampaignSubscriber has exhausted all their mailings.
-
#on_complete_blocks ⇒ Object
:nodoc:.
-
#on_end { ... } ⇒ Object
Callback after a CampaignSubscriber has ended.
-
#on_end_blocks ⇒ Object
:nodoc:.
-
#on_perform { ... } ⇒ Object
Callback before the mailings get processed in a batch.
-
#on_perform_blocks ⇒ Object
:nodoc:.
-
#on_resubscribe { ... } ⇒ Object
Callback after a Caffeinate::CampaignSubscription is ‘#resubscribed!`.
-
#on_resubscribe_blocks ⇒ Object
:nodoc:.
-
#on_skip { ... } ⇒ Object
Callback after a ‘Caffeinate::Mailing` is skipped.
-
#on_skip_blocks ⇒ Object
:nodoc:.
-
#on_subscribe { ... } ⇒ Object
Callback after a Caffeinate::CampaignSubscription is created, and after the Caffeinate::Mailings have been created.
-
#on_subscribe_blocks ⇒ Object
:nodoc:.
-
#on_unsubscribe { ... } ⇒ Object
Callback after a CampaignSubscriber has unsubscribed.
-
#on_unsubscribe_blocks ⇒ Object
:nodoc:.
-
#run_callbacks(name, *args) ⇒ Object
:nodoc:.
Instance Method Details
#after_perform { ... } ⇒ Object
Callback after the all the mailings have been sent.
after_process do |dripper|
Slack.notify(:caffeinate, "Dripper #{dripper.name} sent #{mailings.size} mailings! Whoa!")
end
119 120 121 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 119 def after_perform(&block) after_perform_blocks << block end |
#after_perform_blocks ⇒ Object
:nodoc:
124 125 126 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 124 def after_perform_blocks @after_perform_blocks ||= [] end |
#after_send { ... } ⇒ Object
Callback after a Mailing has been sent.
after_send do |campaign_subscription, mailing, |
Slack.notify(:caffeinate, "A new subscriber to #{campaign_subscription.campaign.name}!")
end
179 180 181 182 183 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 179 def after_send(&block) # return if after_send_blocks.any? { |after| after.source_location == block.source_location } after_send_blocks << block end |
#after_send_blocks ⇒ Object
:nodoc:
186 187 188 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 186 def after_send_blocks @after_send_blocks ||= [] end |
#before_drip { ... } ⇒ Object
Callback before a Drip has called the mailer.
before_drip do |drip, mailing|
Slack.notify(:caffeinate, "#{drip.action_name} is starting")
end
Note: If you want to bail on the mailing for some reason, you need invoke ‘throw(:abort)`
before_drip do |drip, mailing|
if mailing.caffeinate_campaign_subscription.subscriber.trial_ended?
unsubscribe!("Trial ended")
throw(:abort)
end
end
145 146 147 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 145 def before_drip(&block) before_drip_blocks << block end |
#before_drip_blocks ⇒ Object
:nodoc:
150 151 152 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 150 def before_drip_blocks @before_drip_blocks ||= [] end |
#before_perform { ... } ⇒ Object
Callback before the mailings get processed.
before_perform do |dripper|
Slack.notify(:caffeinate, "Dripper is getting ready for mailing! #{dripper.caffeinate_campaign.name}!")
end
85 86 87 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 85 def before_perform(&block) before_perform_blocks << block end |
#before_perform_blocks ⇒ Object
:nodoc:
90 91 92 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 90 def before_perform_blocks @before_perform_blocks ||= [] end |
#before_send { ... } ⇒ Object
Callback before a Mailing has been sent.
before_send do |campaign_subscription, mailing, |
Slack.notify(:caffeinate, "A new subscriber to #{campaign_subscription.campaign.name}!")
end
162 163 164 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 162 def before_send(&block) before_send_blocks << block end |
#before_send_blocks ⇒ Object
:nodoc:
167 168 169 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 167 def before_send_blocks @before_send_blocks ||= [] end |
#before_subscribe(&block) ⇒ Object
37 38 39 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 37 def before_subscribe(&block) before_subscribe_blocks << block end |
#before_subscribe_blocks ⇒ Object
41 42 43 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 41 def before_subscribe_blocks @before_subscribe_blocks ||= [] end |
#callbacks_for(name) ⇒ Object
:nodoc:
33 34 35 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 33 def callbacks_for(name) send("#{name}_blocks") end |
#on_complete { ... } ⇒ Object
Callback after a CampaignSubscriber has exhausted all their mailings.
on_complete do |campaign_sub|
Slack.notify(:caffeinate, "A subscriber completed #{campaign_sub.campaign.name}!")
end
197 198 199 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 197 def on_complete(&block) on_complete_blocks << block end |
#on_complete_blocks ⇒ Object
:nodoc:
202 203 204 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 202 def on_complete_blocks @on_complete_blocks ||= [] end |
#on_end { ... } ⇒ Object
Callback after a CampaignSubscriber has ended.
on_end do |campaign_sub|
Slack.notify(:caffeinate, "#{campaign_sub.id} has ended... sad day.")
end
229 230 231 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 229 def on_end(&block) on_end_blocks << block end |
#on_end_blocks ⇒ Object
:nodoc:
234 235 236 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 234 def on_end_blocks @on_end_blocks ||= [] end |
#on_perform { ... } ⇒ Object
Callback before the mailings get processed in a batch.
after_process do |dripper, mailings|
Slack.notify(:caffeinate, "Dripper #{dripper.name} sent #{mailings.size} mailings! Whoa!")
end
102 103 104 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 102 def on_perform(&block) on_perform_blocks << block end |
#on_perform_blocks ⇒ Object
:nodoc:
107 108 109 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 107 def on_perform_blocks @on_perform_blocks ||= [] end |
#on_resubscribe { ... } ⇒ Object
Callback after a Caffeinate::CampaignSubscription is ‘#resubscribed!`
on_resubscribe do |campaign_subscription|
Slack.notify(:caffeinate, "Someone resubscribed to #{campaign_subscription.campaign.name}!")
end
69 70 71 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 69 def on_resubscribe(&block) on_resubscribe_blocks << block end |
#on_resubscribe_blocks ⇒ Object
:nodoc:
74 75 76 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 74 def on_resubscribe_blocks @on_resubscribe_blocks ||= [] end |
#on_skip { ... } ⇒ Object
Callback after a ‘Caffeinate::Mailing` is skipped.
on_skip do |campaign_subscription, mailing, |
Slack.notify(:caffeinate, "#{campaign_sub.id} has unsubscribed... sad day.")
end
245 246 247 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 245 def on_skip(&block) on_skip_blocks << block end |
#on_skip_blocks ⇒ Object
:nodoc:
250 251 252 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 250 def on_skip_blocks @on_skip_blocks ||= [] end |
#on_subscribe { ... } ⇒ Object
Callback after a Caffeinate::CampaignSubscription is created, and after the Caffeinate::Mailings have been created.
on_subscribe do |campaign_subscription|
Slack.notify(:caffeinate, "A new subscriber to #{campaign_subscription.campaign.name}!")
end
53 54 55 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 53 def on_subscribe(&block) on_subscribe_blocks << block end |
#on_subscribe_blocks ⇒ Object
:nodoc:
58 59 60 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 58 def on_subscribe_blocks @on_subscribe_blocks ||= [] end |
#on_unsubscribe { ... } ⇒ Object
Callback after a CampaignSubscriber has unsubscribed.
on_unsubscribe do |campaign_sub|
Slack.notify(:caffeinate, "#{campaign_sub.id} has unsubscribed... sad day.")
end
213 214 215 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 213 def on_unsubscribe(&block) on_unsubscribe_blocks << block end |
#on_unsubscribe_blocks ⇒ Object
:nodoc:
218 219 220 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 218 def on_unsubscribe_blocks @on_unsubscribe_blocks ||= [] end |
#run_callbacks(name, *args) ⇒ Object
:nodoc:
22 23 24 25 26 27 28 29 30 |
# File 'lib/caffeinate/dripper/callbacks.rb', line 22 def run_callbacks(name, *args) catch(:abort) do callbacks_for(name).each do |callback| callback.call(*args) end return true end false end |