Class: Guard::GoRunner
- Inherits:
-
Object
- Object
- Guard::GoRunner
- Defined in:
- lib/guard/go/runner.rb
Constant Summary collapse
- MAX_WAIT_COUNT =
10
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
- #build_go_command ⇒ Object
-
#initialize(options) ⇒ GoRunner
constructor
A new instance of GoRunner.
- #ps_go_pid ⇒ Object
- #restart ⇒ Object
- #sleep_time ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options) ⇒ GoRunner
Returns a new instance of GoRunner.
7 8 9 10 11 |
# File 'lib/guard/go/runner.rb', line 7 def initialize() @options = raise "Server file not found. Check your :server option in your Guarfile." unless File.exists? @options[:server] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/guard/go/runner.rb', line 5 def @options end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
5 6 7 |
# File 'lib/guard/go/runner.rb', line 5 def pid @pid end |
Instance Method Details
#build_go_command ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/guard/go/runner.rb', line 31 def build_go_command if @options[:test] %{cd #{Dir.pwd} && go test} else %{cd #{Dir.pwd} && go run #{@options[:server]} &} end end |
#ps_go_pid ⇒ Object
39 40 41 |
# File 'lib/guard/go/runner.rb', line 39 def ps_go_pid `ps aux | awk '/a.out/&&!/awk/{print $2;}'`.split("\n").map { |pid| pid.to_i } end |
#restart ⇒ Object
26 27 28 29 |
# File 'lib/guard/go/runner.rb', line 26 def restart stop start end |
#sleep_time ⇒ Object
43 44 45 |
# File 'lib/guard/go/runner.rb', line 43 def sleep_time [:timeout].to_f / MAX_WAIT_COUNT.to_f end |
#start ⇒ Object
13 14 15 |
# File 'lib/guard/go/runner.rb', line 13 def start run_go_command! end |
#stop ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/guard/go/runner.rb', line 17 def stop ps_go_pid.each do |pid| system %{kill -KILL #{pid}} end while ps_go_pid.count > 0 sleep sleep_time end end |