Class: Guard::Process
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::Process
- Defined in:
- lib/guard/process.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Process
constructor
A new instance of Process.
- #process_running? ⇒ Boolean
- #reload ⇒ Object
- #run_all ⇒ Object
- #run_on_change(paths) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #wait_for_stop ⇒ Object
- #wait_for_stop? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Process
Returns a new instance of Process.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/guard/process.rb', line 6 def initialize( = {}) @pid = nil @command = .fetch(:command) @command = @command.split(" ") if @command.is_a?(String) @env = [:env] || {} @name = [:name] @dir = [:dir] || Dir.getwd @stop_signal = [:stop_signal] || "TERM" @dont_stop = [:dont_stop] super end |
Instance Method Details
#process_running? ⇒ Boolean
22 23 24 25 26 27 28 |
# File 'lib/guard/process.rb', line 22 def process_running? begin @pid ? ::Process.kill(0, @pid) : false rescue Errno::ESRCH => e false end end |
#reload ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/guard/process.rb', line 67 def reload if wait_for_stop? wait_for_stop else stop end start end |
#run_all ⇒ Object
76 77 78 |
# File 'lib/guard/process.rb', line 76 def run_all true end |
#run_on_change(paths) ⇒ Object
80 81 82 |
# File 'lib/guard/process.rb', line 80 def run_on_change(paths) reload end |
#start ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/guard/process.rb', line 30 def start UI.info("Starting process #{@name}") original_env = {} @env.each_pair do |key, value| original_env[key] = ENV[key] ENV[key] = value end Dir.chdir(@dir) do @pid = Spoon.spawnp(*@command) end original_env.each_pair do |key, value| ENV[key] = value end UI.info("Started process #{@name}") end |
#stop ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/guard/process.rb', line 46 def stop if @pid UI.info("Stopping process #{@name}") begin ::Process.kill(@stop_signal, @pid) ::Process.waitpid(@pid) rescue Errno::ESRCH end @pid = nil UI.info("Stopped process #{@name}") end end |
#wait_for_stop ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/guard/process.rb', line 59 def wait_for_stop if @pid UI.info("Process #{@name} is still running...") ::Process.waitpid(@pid) rescue Errno::ESRCH UI.info("Process #{@name} has stopped!") end end |
#wait_for_stop? ⇒ Boolean
18 19 20 |
# File 'lib/guard/process.rb', line 18 def wait_for_stop? @dont_stop end |