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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Drip.



13
14
15
16
17
18
# File 'lib/caffeinate/drip.rb', line 13

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.



11
12
13
# File 'lib/caffeinate/drip.rb', line 11

def action
  @action
end

#blockObject (readonly)

Returns the value of attribute block.



11
12
13
# File 'lib/caffeinate/drip.rb', line 11

def block
  @block
end

#dripperObject (readonly)

Returns the value of attribute dripper.



11
12
13
# File 'lib/caffeinate/drip.rb', line 11

def dripper
  @dripper
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/caffeinate/drip.rb', line 11

def options
  @options
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)


33
34
35
36
37
38
39
40
41
42
# File 'lib/caffeinate/drip.rb', line 33

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)


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

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

#send_at(mailing = nil) ⇒ Object



25
26
27
# File 'lib/caffeinate/drip.rb', line 25

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