Class: Guard::RailsRunner
- Inherits:
-
Object
- Object
- Guard::RailsRunner
- Defined in:
- lib/guard/rails/runner.rb
Constant Summary collapse
- MAX_WAIT_COUNT =
10
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #build_rails_command ⇒ Object
-
#initialize(options) ⇒ RailsRunner
constructor
A new instance of RailsRunner.
- #pid ⇒ Object
- #pid_file ⇒ Object
- #restart ⇒ Object
- #sleep_time ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options) ⇒ RailsRunner
Returns a new instance of RailsRunner.
9 10 11 |
# File 'lib/guard/rails/runner.rb', line 9 def initialize() @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/guard/rails/runner.rb', line 7 def @options end |
Instance Method Details
#build_rails_command ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/guard/rails/runner.rb', line 36 def build_rails_command return %{#{[:CLI]} --pid #{pid_file}} if [:CLI] = [ [:daemon] ? '-d' : nil, [:debugger] ? '-u' : nil, '-e', [:environment], '--pid', pid_file, '-p', [:port], [:server], ] = [ [:zeus_plan] || 'server', ] # omit env when use zeus rails_runner = [:zeus] ? "zeus #{.join(' ')}" : "RAILS_ENV=#{[:environment]} rails server" %{#{rails_runner} #{.join(' ')}} end |
#pid ⇒ Object
62 63 64 |
# File 'lib/guard/rails/runner.rb', line 62 def pid File.file?(pid_file) ? File.read(pid_file).to_i : nil end |
#pid_file ⇒ Object
58 59 60 |
# File 'lib/guard/rails/runner.rb', line 58 def pid_file File.([:pid_file] || "tmp/pids/#{[:environment]}.pid") end |
#restart ⇒ Object
31 32 33 34 |
# File 'lib/guard/rails/runner.rb', line 31 def restart stop start end |
#sleep_time ⇒ Object
66 67 68 |
# File 'lib/guard/rails/runner.rb', line 66 def sleep_time [:timeout].to_f / MAX_WAIT_COUNT.to_f end |
#start ⇒ Object
13 14 15 16 17 |
# File 'lib/guard/rails/runner.rb', line 13 def start kill_unmanaged_pid! if [:force_run] run_rails_command! wait_for_pid end |
#stop ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/guard/rails/runner.rb', line 19 def stop if File.file?(pid_file) pid = File.read(pid_file).strip system %{kill -SIGINT #{pid}} wait_for_no_pid if $?.exitstatus == 0 # If you lost your pid_file, you are already died. system %{kill -KILL #{pid} >&2 2>/dev/null} FileUtils.rm pid_file, :force => true end end |