Class: Guard::Faye

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Faye.



10
11
12
13
14
15
# File 'lib/guard/faye.rb', line 10

def initialize(watchers = [], options = {})
  super

  @current_path = options[:path]
  @faye_init = options[:config]
end

Instance Method Details

#reloadObject



42
43
44
45
# File 'lib/guard/faye.rb', line 42

def reload
  stop
  start
end

#run_on_change(paths) ⇒ Object



47
48
49
# File 'lib/guard/faye.rb', line 47

def run_on_change(paths)
  reload
end

#startObject



17
18
19
20
21
22
23
24
25
# File 'lib/guard/faye.rb', line 17

def start
  cmd = "cd #{@current_path} && bundle exec rackup #{@current_path}/#{@faye_init} -s thin -E test"
  
  result = ''
  
  Thread.new do
    result = %x[#{cmd}]    
  end
end

#stopObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/guard/faye.rb', line 27

def stop
  parent_pids = []

  Sys::ProcTable.ps.each do |ps|
    if ps.cmdline =~ /faye_test\.ru/i
      parent_pids << ps.pid
      Process.kill('KILL', ps.pid)
    end

    if parent_pids.include? ps.ppid
      Process.kill('KILL', ps.pid)
    end
  end
end