Class: Guard::Process
Instance Method Summary collapse
-
#initialize(watchers = [], 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
Constructor Details
#initialize(watchers = [], options = {}) ⇒ Process
Returns a new instance of Process.
7 8 9 10 11 12 13 14 15 |
# File 'lib/guard/process.rb', line 7 def initialize(watchers = [], = {}) @pid = nil @command = .fetch(:command).split(" ") @env = [:env] || {} @name = [:name] @dir = [:dir] || Dir.getwd @stop_signal = [:stop_signal] || "TERM" super end |
Instance Method Details
#process_running? ⇒ Boolean
17 18 19 20 21 22 23 |
# File 'lib/guard/process.rb', line 17 def process_running? begin @pid ? ::Process.kill(0, @pid) : false rescue Errno::ESRCH => e false end end |
#reload ⇒ Object
51 52 53 54 |
# File 'lib/guard/process.rb', line 51 def reload stop start end |
#run_all ⇒ Object
56 57 58 |
# File 'lib/guard/process.rb', line 56 def run_all true end |
#run_on_change(paths) ⇒ Object
60 61 62 |
# File 'lib/guard/process.rb', line 60 def run_on_change(paths) reload end |
#start ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/guard/process.rb', line 25 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
41 42 43 44 45 46 47 48 49 |
# File 'lib/guard/process.rb', line 41 def stop if @pid UI.info("Stopping process #{@name}") ::Process.kill(@stop_signal, @pid) ::Process.waitpid(@pid) rescue Errno::ESRCH @pid = nil UI.info("Stopped process #{@name}") end end |