Module: Motion::Component::PeriodicTimers::ModuleFunctions

Included in:
Motion::Component::PeriodicTimers
Defined in:
lib/motion/component/periodic_timers.rb

Overview

Analogous to ‘module_function` (available on both class and instance)

Instance Method Summary collapse

Instance Method Details

#every(interval, handler, name: handler) ⇒ Object



18
19
20
# File 'lib/motion/component/periodic_timers.rb', line 18

def every(interval, handler, name: handler)
  periodic_timer(name, handler, every: interval)
end

#periodic_timer(name, handler = name, every:) ⇒ Object



22
23
24
25
# File 'lib/motion/component/periodic_timers.rb', line 22

def periodic_timer(name, handler = name, every:)
  self._periodic_timers =
    _periodic_timers.merge(name.to_s => [handler.to_sym, every]).freeze
end

#periodic_timersObject



32
33
34
# File 'lib/motion/component/periodic_timers.rb', line 32

def periodic_timers
  _periodic_timers.transform_values { |_handler, interval| interval }
end

#stop_periodic_timer(name) ⇒ Object



27
28
29
30
# File 'lib/motion/component/periodic_timers.rb', line 27

def stop_periodic_timer(name)
  self._periodic_timers =
    _periodic_timers.except(name.to_s).freeze
end