Class: Caffeinate::ScheduleEvaluator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(drip, mailing) ⇒ ScheduleEvaluator

Returns a new instance of ScheduleEvaluator.



28
29
30
31
# File 'lib/caffeinate/schedule_evaluator.rb', line 28

def initialize(drip, mailing)
  @drip = drip
  @mailing = mailing
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



60
61
62
# File 'lib/caffeinate/schedule_evaluator.rb', line 60

def method_missing(method, *args, &block)
  @drip.send(method, *args, &block)
end

Instance Attribute Details

#mailingObject (readonly)

Returns the value of attribute mailing.



27
28
29
# File 'lib/caffeinate/schedule_evaluator.rb', line 27

def mailing
  @mailing
end

Class Method Details

.call(drip, mailing) ⇒ Object



23
24
25
# File 'lib/caffeinate/schedule_evaluator.rb', line 23

def self.call(drip, mailing)
  new(drip, mailing).call
end

Instance Method Details

#callObject

todo: test this decision tree.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/caffeinate/schedule_evaluator.rb', line 34

def call
  if periodical?
    start = mailing.instance_exec(&options[:start])
    start += options[:every] if mailing.caffeinate_campaign_subscription.caffeinate_mailings.count.positive?
    date = start.from_now
  elsif options[:on]
    date = OptionEvaluator.new(options[:on], self, mailing).call
  else
    date = OptionEvaluator.new(options[:delay], self, mailing).call
    if date.respond_to?(:from_now)
      date = date.from_now
    end
  end

  if options[:at]
    time = OptionEvaluator.new(options[:at], self, mailing).call
    return date.change(hour: time.hour, min: time.min, sec: time.sec)
  end

  date
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/caffeinate/schedule_evaluator.rb', line 56

def respond_to_missing?(name, include_private = false)
  @drip.respond_to?(name, include_private)
end