Class: Thyme::Timer
- Inherits:
-
Object
- Object
- Thyme::Timer
- Defined in:
- lib/thyme/timer.rb
Overview
The actual timer logic where you can pause, unpause, or stop one or more timers
Instance Method Summary collapse
-
#initialize(config) ⇒ Timer
constructor
A new instance of Timer.
- #run ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(config) ⇒ Timer
Returns a new instance of Timer.
4 5 6 7 8 |
# File 'lib/thyme/timer.rb', line 4 def initialize(config) @config = config @format = Format.new(config) @tmux = Tmux.new(config) end |
Instance Method Details
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/thyme/timer.rb', line 14 def run # pause/unpause timer if it's already running send_signal('USR1') and return if File.exists?(Config::PID_FILE) begin File.open(Config::PID_FILE, "w") { |f| f.print(Process.pid) } @tmux.open if @config.repeat == 1 run_single else while @config.repeat_index <= @config.repeat || @config.repeat == 0 @config.break = false run_single if @config.repeat_index < @config.repeat || @config.repeat == 0 @config.break = true run_single end @config.repeat_index += 1 end end rescue Thyme::StopTimer # stop signal received ensure @tmux.close File.delete(Config::PID_FILE) if File.exists?(Config::PID_FILE) end end |
#stop ⇒ Object
10 11 12 |
# File 'lib/thyme/timer.rb', line 10 def stop send_signal('TERM') end |