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.
6 7 8 9 10 11 12 13 14 |
# File 'lib/guard/process.rb', line 6 def initialize(watchers = [], = {}) @process = nil @pid = nil @command = .fetch(:command).split @env = [:env] @name = [:name] @stop_signal = [:stop_signal] || "TERM" super end |
Instance Method Details
#process_running? ⇒ Boolean
16 17 18 19 20 21 22 |
# File 'lib/guard/process.rb', line 16 def process_running? begin @pid ? ::Process.kill(0, @pid) : false rescue Errno::ESRCH => e false end end |
#reload ⇒ Object
43 44 45 46 |
# File 'lib/guard/process.rb', line 43 def reload stop start end |
#run_all ⇒ Object
48 49 50 |
# File 'lib/guard/process.rb', line 48 def run_all true end |
#run_on_change(paths) ⇒ Object
52 53 54 |
# File 'lib/guard/process.rb', line 52 def run_on_change(paths) reload end |
#start ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/guard/process.rb', line 24 def start UI.info("Starting process #{@name}") @command.unshift(@env) if @env @process = IO.popen(@command) UI.info("Started process #{@name}") @pid = @process.pid end |
#stop ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/guard/process.rb', line 32 def stop if @process UI.info("Stopping process #{@name}") ::Process.kill(@stop_signal, @process.pid) ::Process.waitpid(@pid) rescue Errno::ESRCH @process.close @pid = nil UI.info("Stopped process #{@name}") end end |