lib/guard/rails/runner.rb in guard-rails-0.4.6 vs lib/guard/rails/runner.rb in guard-rails-0.4.7

- old
+ new

@@ -16,18 +16,18 @@ run_rails_command! wait_for_pid end def stop - if File.file?(pid_file) + if has_pid? pid = File.read(pid_file).strip.to_i sig_sent = kill_process("INT", pid) wait_for_no_pid if sig_sent # If you lost your pid_file, you are already died. kill_process("KILL", pid) - FileUtils.rm pid_file, :force => true + remove_pid_file_and_wait_for_no_pid end end def restart stop @@ -54,11 +54,11 @@ def pid_file File.expand_path(options[:pid_file] || File.join(@root, "tmp/pids/#{options[:environment]}.pid")) end def pid - File.file?(pid_file) ? File.read(pid_file).to_i : nil + has_pid? ? File.read(pid_file).to_i : nil end def sleep_time options[:timeout].to_f / MAX_WAIT_COUNT.to_f end @@ -108,12 +108,11 @@ end def kill_unmanaged_pid! if pid = unmanaged_pid kill_process("KILL", pid) - FileUtils.rm pid_file - wait_for_no_pid + remove_pid_file_and_wait_for_no_pid end end def unmanaged_pid file_list = `lsof -n -i TCP:#{options[:port]}` @@ -126,19 +125,26 @@ end private def wait_for_pid - wait_for_pid_loop + wait_for_pid_loop { has_pid? } end def wait_for_no_pid - wait_for_pid_loop(false) + wait_for_pid_loop { !has_pid? } end - def wait_for_pid_loop(check_for_existince = true) + def remove_pid_file_and_wait_for_no_pid + wait_for_pid_loop do + FileUtils.rm pid_file, :force => true + !has_pid? + end + end + + def wait_for_pid_loop count = 0 - while !(check_for_existince ? has_pid? : !has_pid?) && count < MAX_WAIT_COUNT + while !yield && count < MAX_WAIT_COUNT wait_for_pid_action count += 1 end !(count == MAX_WAIT_COUNT) end