Module: RubyClock::AroundActions

Included in:
RubyClock
Defined in:
lib/ruby-clock/around_actions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#around_actionsObject

Returns the value of attribute around_actions.



3
4
5
# File 'lib/ruby-clock/around_actions.rb', line 3

def around_actions
  @around_actions
end

Instance Method Details

#call_with_around_action_stack(wrappers, job_proc, job_info) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ruby-clock/around_actions.rb', line 33

def call_with_around_action_stack(wrappers, job_proc, job_info)
  case wrappers.count
  when 0
    job_proc.call(job_info)
  else
    call_with_around_action_stack(
      wrappers[1..],
      Proc.new{ wrappers.first.call(job_proc, job_info) },
      job_info
    )
  end
end

#ensure_around_trigger_has_not_been_redefinedObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby-clock/around_actions.rb', line 22

def ensure_around_trigger_has_not_been_redefined
  if around_trigger_code_location != schedule.method(:around_trigger).source_location
    raise <<~MESSAGE

      You need to change your around_trigger definition to use around_actions instead.

      It's easy and fun! https://github.com/jjb/ruby-clock/blob/main/CHANGELOG.md#migrating-from-ruby-clock-version-1-to-version-2
    MESSAGE
  end
end

#freeze_around_actionsObject



5
6
7
# File 'lib/ruby-clock/around_actions.rb', line 5

def freeze_around_actions
  @around_actions.freeze
end

#set_up_around_actionsObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ruby-clock/around_actions.rb', line 9

def set_up_around_actions
  @around_actions = []
  def schedule.around_trigger(job_info, &job_proc)
    RubyClock.instance.call_with_around_action_stack(
      RubyClock.instance.around_actions.reverse,
      job_proc,
      job_info
    )
  end

  self.around_trigger_code_location = schedule.method(:around_trigger).source_location
end