Module: Caffeinate::Dripper::Drip::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#drip(action_name, options = {}, &block) ⇒ Object

Register a drip on the Dripper

drip :mailer_action_name, mailer_class: "MailerClass", step: 1, delay: 1.hour

Accepts a block, symbol (an instance method on the Dripper that accepts two arguments: drip, mailing), or a string to be later parsed into a Time object.

drip :mailer_action_name, mailer_class: "MailerClass", at: -> { 3.days.from_now.in_time_zone(mailing.subscriber.timezone) }

class MyDripper
  drip :mailer_action_name, mailer_class: "MailerClass", at: :generate_date
  def generate_date(drip, mailing)
    3.days.from_now.in_time_zone(mailing.subscriber.timezone)
  end
end

drip :mailer_action_name, mailer_class: "MailerClass", at: 'January 1, 2022'

Parameters:

  • action_name (Symbol)

    the name of the mailer action

  • options (Hash) (defaults to: {})

    the options to create a drip with

Options Hash (options):

  • :mailer_class (String)

    The mailer_class

  • :step (Integer)

    The order in which the drip is executed

  • :delay (ActiveSupport::Duration)

    When the drip should be ran

  • :at (Block|Symbol|String)

    Alternative to ‘:delay` option, allowing for more fine-tuned timing.

  • :using (Symbol)

    Set to ‘:parameters` if the mailer action uses ActionMailer::Parameters



49
50
51
# File 'lib/caffeinate/dripper/drip.rb', line 49

def drip(action_name, options = {}, &block)
  drip_collection.register(action_name, options, ::Caffeinate::Drip, &block)
end

#drip_collectionObject

A collection of Drip objects associated with a given ‘Caffeinate::Dripper`



15
16
17
# File 'lib/caffeinate/dripper/drip.rb', line 15

def drip_collection
  @drip_collection ||= DripCollection.new(self)
end

#dripsObject

A collection of Drip objects associated with a given ‘Caffeinate::Dripper`



20
21
22
# File 'lib/caffeinate/dripper/drip.rb', line 20

def drips
  drip_collection.values
end

#periodical_drip(action_name, options = {}, &block) ⇒ Object

Register a Periodical drip on the Dripper

periodical :pay_your_invoice, every: 1.day, start: 0.hours, if: :invoice_unpaid?

Parameters:

  • action_name (Symbol)

    the name of the mailer action

  • options (Hash) (defaults to: {})

    the options to create a drip with

Options Hash (options):

  • :mailer_class (String)

    The mailer_class

  • :every (Symbol|Proc|ActiveSupport::Duration)

    How often the mailing should be created

  • :if (Symbol|Proc)

    If the periodical should create another mailing

  • :start (Symbol|Proc)

    The offset time to start the clock (only used on the first mailing creation)

    periodical :pay_your_invoice, mailer_class: “InvoiceReminderMailer”, if: :invoice_unpaid?

    class MyDripper

    drip :mailer_action_name, mailer_class: "MailerClass", at: :generate_date
    def generate_date(drip, mailing)
      3.days.from_now.in_time_zone(mailing.subscriber.timezone)
    end
    

    end

    drip :mailer_action_name, mailer_class: “MailerClass”, at: ‘January 1, 2022’

  • :using (Symbol)

    Set to ‘:parameters` if the mailer action uses ActionMailer::Parameters



76
77
78
# File 'lib/caffeinate/dripper/drip.rb', line 76

def periodical_drip(action_name, options = {}, &block)
  drip_collection.register(action_name, options, ::Caffeinate::PeriodicalDrip, &block)
end