class Caffeinate::Drip

A Drip object

Handles the block and provides convenience methods for the drip

Constants

ALL_DRIP_OPTIONS
VALID_DRIP_OPTIONS

Attributes

action[R]
block[R]
dripper[R]
options[R]

Public Class Methods

build(dripper, action, options, &block) click to toggle source
# File lib/caffeinate/drip.rb, line 15
def build(dripper, action, options, &block)
  options = options.with_defaults(dripper.defaults)
  validate_drip_options(dripper, action, options)

  new(dripper, action, options, &block)
end
new(dripper, action, options, &block) click to toggle source
# File lib/caffeinate/drip.rb, line 49
def initialize(dripper, action, options, &block)
  @dripper = dripper
  @action = action
  @options = options
  @block = block
end

Private Class Methods

normalize_options(dripper, options) click to toggle source
# File lib/caffeinate/drip.rb, line 38
def normalize_options(dripper, options)
  options[:mailer_class] ||= options[:mailer] || dripper.defaults[:mailer_class]
  options[:using] ||= dripper.defaults[:using]
  options[:step] ||= dripper.drips.size + 1

  options
end
validate_drip_options(dripper, action, options) click to toggle source
# File lib/caffeinate/drip.rb, line 24
def validate_drip_options(dripper, action, options)
  options = normalize_options(dripper, options)

  if options[:mailer_class].nil? && options[:action_class].nil?
    raise ArgumentError, "You must define :mailer_class, :mailer, or :action_class in the options for #{action.inspect} on #{dripper.inspect}"
  end

  if options[:every].nil? && options[:delay].nil? && options[:on].nil?
    raise ArgumentError, "You must define :delay or :on or :every in the options for #{action.inspect} on #{dripper.inspect}"
  end

  options
end

Public Instance Methods

enabled?(mailing) click to toggle source

Checks if the drip is enabled

This is kind of messy and could use some love. todo: better.

# File lib/caffeinate/drip.rb, line 69
def enabled?(mailing)
  catch(:abort) do
    if dripper.run_callbacks(:before_drip, self, mailing)
      return DripEvaluator.new(mailing).call(&@block)
    else
      return false
    end
  end
  false
end
parameterized?() click to toggle source

If the associated ActionMailer uses ‘ActionMailer::Parameterized` initialization instead of argument-based initialization

# File lib/caffeinate/drip.rb, line 57
def parameterized?
  options[:using] == :parameterized
end
send_at(mailing = nil) click to toggle source
# File lib/caffeinate/drip.rb, line 61
def send_at(mailing = nil)
  ::Caffeinate::ScheduleEvaluator.call(self, mailing)
end
type() click to toggle source

allows for hitting type.periodical? or type.drip?

# File lib/caffeinate/drip.rb, line 81
def type
  name = self.class.name.demodulize.delete_suffix("Drip").presence || "Drip"

  ActiveSupport::StringInquirer.new(name.downcase)
end