Class: Guard::Rackup::Runner
- Inherits:
-
Object
- Object
- Guard::Rackup::Runner
- Defined in:
- lib/guard/rackup/runner.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :command => "rackup ./config.ru -E development", :start => proc{ Process.spawn(command) }, :stop => proc{|pid| Process.kill("INT", pid); Process.wait pid}, :reload => proc{ stop; start }, }
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #command ⇒ Object
-
#initialize(options) ⇒ Runner
constructor
A new instance of Runner.
- #reload ⇒ Object
- #restart ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options) ⇒ Runner
Returns a new instance of Runner.
13 14 15 16 |
# File 'lib/guard/rackup/runner.rb', line 13 def initialize() @pid = nil @options = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/guard/rackup/runner.rb', line 11 def @options end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
11 12 13 |
# File 'lib/guard/rackup/runner.rb', line 11 def pid @pid end |
Instance Method Details
#alive? ⇒ Boolean
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/guard/rackup/runner.rb', line 45 def alive? return false unless @pid begin Process.getpgid(@pid) true rescue Errno::ESRCH => e false end end |
#command ⇒ Object
41 42 43 |
# File 'lib/guard/rackup/runner.rb', line 41 def command @options[:command] end |
#reload ⇒ Object
32 33 34 |
# File 'lib/guard/rackup/runner.rb', line 32 def reload instance_eval &@options[:reload] end |
#restart ⇒ Object
36 37 38 39 |
# File 'lib/guard/rackup/runner.rb', line 36 def restart stop if alive? start end |
#start ⇒ Object
18 19 20 21 |
# File 'lib/guard/rackup/runner.rb', line 18 def start return @pid if alive? @pid = instance_eval &@options[:start] end |
#stop ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/guard/rackup/runner.rb', line 23 def stop if alive? instance_eval do @options[:stop].call(@pid) @pid = nil end end end |