Module: Caffeinate::Dripper::Periodical::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#periodical(action_name, every:, start: -> { ::Caffeinate.config.time_now }, **options, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/caffeinate/dripper/periodical.rb', line 11

def periodical(action_name, every:, start: -> { ::Caffeinate.config.time_now }, **options, &block)
  options[:start] = start
  options[:every] = every
  periodical_drip(action_name, **options, &block)

  after_send do |mailing, _message|
    make_email = -> {
      next_mailing = mailing.dup
      next_mailing.send_at = mailing.drip.send_at(mailing)
      next_mailing.save!
    }
    if mailing.drip.action == action_name
      if condition = mailing.drip.options[:if]
        if OptionEvaluator.new(condition, mailing.drip, mailing).call
          make_email.call
        end
      else
        make_email.call
      end
    end
  end
end