Class: Guard::Clockwork

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/clockwork.rb

Constant Summary collapse

DEFAULT_CLOCKFILE =
'config/clock.rb'

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ Clockwork

Returns a new instance of Clockwork.



9
10
11
12
13
14
# File 'lib/guard/clockwork.rb', line 9

def initialize(watchers = [], options = {})
  @options = options
  @pid = nil
  @clockfile = options[:clockfile] || DEFAULT_CLOCKFILE
  super
end

Instance Method Details

#reloadObject

Called on Ctrl-Z signal



38
39
40
41
# File 'lib/guard/clockwork.rb', line 38

def reload
  UI.info 'Restarting clockwork...'
  restart
end

#restartObject



53
54
55
56
# File 'lib/guard/clockwork.rb', line 53

def restart
  stop
  start
end

#run_allObject

Called on Ctrl-/ signal



44
45
46
# File 'lib/guard/clockwork.rb', line 44

def run_all
  true
end

#run_on_changes(paths) ⇒ Object

Called on file(s) modifications



49
50
51
# File 'lib/guard/clockwork.rb', line 49

def run_on_changes(paths)
  restart
end

#startObject



16
17
18
19
20
21
22
# File 'lib/guard/clockwork.rb', line 16

def start
  stop
  UI.info 'Starting up clockwork...'
  UI.info cmd

  @pid = spawn({}, cmd)
end

#stopObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/guard/clockwork.rb', line 24

def stop
  if @pid
    UI.info 'Stopping clockwork...'
    ::Process.kill :INT, @pid
    ::Process.wait @pid
    UI.info 'Stopped process clockwork'
  end
rescue Errno::ESRCH
  UI.info 'Guard::Clockwork lost the subprocess!'
ensure
  @pid = nil
end