Class: Caffeinate::Drip

Inherits:
Object
  • Object
show all
Defined in:
lib/caffeinate/drip.rb

Overview

A Drip object

Handles the block and provides convenience methods for the drip

Direct Known Subclasses

PeriodicalDrip

Constant Summary collapse

ALL_DRIP_OPTIONS =
[:mailer_class, :mailer, :start, :using, :step]
VALID_DRIP_OPTIONS =
ALL_DRIP_OPTIONS + [:delay, :start, :at, :on].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dripper, action, options, &block) ⇒ Drip

Returns a new instance of Drip.



49
50
51
52
53
54
# File 'lib/caffeinate/drip.rb', line 49

def initialize(dripper, action, options, &block)
  @dripper = dripper
  @action = action
  @options = options
  @block = block
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



47
48
49
# File 'lib/caffeinate/drip.rb', line 47

def action
  @action
end

#blockObject (readonly)

Returns the value of attribute block.



47
48
49
# File 'lib/caffeinate/drip.rb', line 47

def block
  @block
end

#dripperObject (readonly)

Returns the value of attribute dripper.



47
48
49
# File 'lib/caffeinate/drip.rb', line 47

def dripper
  @dripper
end

#optionsObject (readonly)

Returns the value of attribute options.



47
48
49
# File 'lib/caffeinate/drip.rb', line 47

def options
  @options
end

Class Method Details

.build(dripper, action, options, &block) ⇒ Object



15
16
17
18
19
20
# 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

Instance Method Details

#enabled?(mailing) ⇒ Boolean

Checks if the drip is enabled

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

Returns:

  • (Boolean)


69
70
71
72
73
74
75
76
77
78
# 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?Boolean

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

Returns:

  • (Boolean)


57
58
59
# File 'lib/caffeinate/drip.rb', line 57

def parameterized?
  options[:using] == :parameterized
end

#send_at(mailing = nil) ⇒ Object



61
62
63
# File 'lib/caffeinate/drip.rb', line 61

def send_at(mailing = nil)
  ::Caffeinate::ScheduleEvaluator.call(self, mailing)
end

#typeObject

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



81
82
83
84
85
# 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