Class: Guard::Rackup::Runner

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options)
  @pid = nil
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/guard/rackup/runner.rb', line 11

def options
  @options
end

#pidObject (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

Returns:

  • (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

#commandObject



41
42
43
# File 'lib/guard/rackup/runner.rb', line 41

def command
  @options[:command]
end

#reloadObject



32
33
34
# File 'lib/guard/rackup/runner.rb', line 32

def reload
  instance_eval &@options[:reload]
end

#restartObject



36
37
38
39
# File 'lib/guard/rackup/runner.rb', line 36

def restart
  stop if alive?
  start
end

#startObject



18
19
20
21
# File 'lib/guard/rackup/runner.rb', line 18

def start
  return @pid if alive?
  @pid = instance_eval &@options[:start]
end

#stopObject



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