Module: Caffeinate::Dripper::Callbacks::ClassMethods

Defined in:
lib/caffeinate/dripper/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#after_send { ... } ⇒ Object

Callback after a Mailing has been sent.

after_send do |campaign_subscription, mailing, message|
  Slack.notify(:caffeinate, "A new subscriber to #{campaign_subscription.campaign.name}!")
end

Yields:

  • Caffeinate::CampaignSubscription

  • Caffeinate::Mailing

  • Mail::Message



81
82
83
# File 'lib/caffeinate/dripper/callbacks.rb', line 81

def after_send(&block)
  after_send_blocks << block
end

#after_send_blocksObject

:nodoc:



86
87
88
# File 'lib/caffeinate/dripper/callbacks.rb', line 86

def after_send_blocks
  @after_send_blocks ||= []
end

#before_drip { ... } ⇒ Object

Callback before a Drip has called the mailer.

before_drip do |campaign_subscription, mailing, drip|
  Slack.notify(:caffeinate, "#{drip.action_name} is starting")
end

Yields:

  • Caffeinate::CampaignSubscription

  • Caffeinate::Mailing

  • Caffeinate::Drip current drip



45
46
47
# File 'lib/caffeinate/dripper/callbacks.rb', line 45

def before_drip(&block)
  before_drip_blocks << block
end

#before_drip_blocksObject

:nodoc:



50
51
52
# File 'lib/caffeinate/dripper/callbacks.rb', line 50

def before_drip_blocks
  @before_drip_blocks ||= []
end

#before_send { ... } ⇒ Object

Callback before a Mailing has been sent.

before_send do |campaign_subscription, mailing, message|
  Slack.notify(:caffeinate, "A new subscriber to #{campaign_subscription.campaign.name}!")
end

Yields:

  • Caffeinate::CampaignSubscription

  • Caffeinate::Mailing

  • Mail::Message



63
64
65
# File 'lib/caffeinate/dripper/callbacks.rb', line 63

def before_send(&block)
  before_send_blocks << block
end

#before_send_blocksObject

:nodoc:



68
69
70
# File 'lib/caffeinate/dripper/callbacks.rb', line 68

def before_send_blocks
  @before_send_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

Yields:

  • Caffeinate::CampaignSubscription



97
98
99
# File 'lib/caffeinate/dripper/callbacks.rb', line 97

def on_complete(&block)
  on_complete_blocks << block
end

#on_complete_blocksObject

:nodoc:



102
103
104
# File 'lib/caffeinate/dripper/callbacks.rb', line 102

def on_complete_blocks
  @on_complete_blocks ||= []
end

#on_skip { ... } ⇒ Object

Callback after a ‘Caffeinate::Mailing` is skipped.

on_skip do |campaign_subscription, mailing, message|
  Slack.notify(:caffeinate, "#{campaign_sub.id} has unsubscribed... sad day.")
end

Yields:

  • Caffeinate::CampaignSubscription

  • Caffeinate::Mailing



130
131
132
# File 'lib/caffeinate/dripper/callbacks.rb', line 130

def on_skip(&block)
  on_skip_blocks << block
end

#on_skip_blocksObject

:nodoc:



135
136
137
# File 'lib/caffeinate/dripper/callbacks.rb', line 135

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

Yields:

  • Caffeinate::CampaignSubscription



27
28
29
# File 'lib/caffeinate/dripper/callbacks.rb', line 27

def on_subscribe(&block)
  on_subscribe_blocks << block
end

#on_subscribe_blocksObject

:nodoc:



32
33
34
# File 'lib/caffeinate/dripper/callbacks.rb', line 32

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

Yields:

  • Caffeinate::CampaignSubscription



113
114
115
# File 'lib/caffeinate/dripper/callbacks.rb', line 113

def on_unsubscribe(&block)
  on_unsubscribe_blocks << block
end

#on_unsubscribe_blocksObject

:nodoc:



118
119
120
# File 'lib/caffeinate/dripper/callbacks.rb', line 118

def on_unsubscribe_blocks
  @on_unsubscribe_blocks ||= []
end

#run_callbacks(name, *args) ⇒ Object

:nodoc:



13
14
15
16
17
# File 'lib/caffeinate/dripper/callbacks.rb', line 13

def run_callbacks(name, *args)
  send("#{name}_blocks").each do |callback|
    callback.call(*args)
  end
end