Class: Guard::Gulp

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

Constant Summary collapse

DEFAULT_SIGNAL =
:QUIT

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Gulp.



8
9
10
11
12
# File 'lib/guard/gulp.rb', line 8

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

Instance Method Details

#reloadObject

Called on Ctrl-Z signal



45
46
47
48
# File 'lib/guard/gulp.rb', line 45

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

#restartObject



60
61
62
63
# File 'lib/guard/gulp.rb', line 60

def restart
  stop
  start
end

#run_allObject

Called on Ctrl-/ signal



51
52
53
# File 'lib/guard/gulp.rb', line 51

def run_all
  true
end

#run_on_changes(paths) ⇒ Object

Called on file(s) modifications



56
57
58
# File 'lib/guard/gulp.rb', line 56

def run_on_changes(paths)
  restart
end

#startObject



14
15
16
17
18
19
20
# File 'lib/guard/gulp.rb', line 14

def start
  stop
  UI.info 'Starting gulp...'
  UI.info cmd

  @pid = spawn(env, cmd)
end

#stopObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/guard/gulp.rb', line 22

def stop
  if @pid
    UI.info 'Stopping gulp...'
    UI.info 'Stopped process gulp'
    ::Process.kill DEFAULT_SIGNAL, @pid
    begin
      Timeout.timeout(15) do
        ::Process.wait @pid
      end
    rescue Timeout::Error
      UI.info 'Sending SIGKILL to gulp, as it\'s taking too long to shutdown.'
      ::Process.kill :KILL, @pid
      ::Process.wait @pid
    end
    UI.info 'Stopped process guard'
  end
rescue Errno::ESRCH
  UI.info 'Guard::Gulp lost the Gulp subprocess!'
ensure
  @pid = nil
end