Class: Guard::Rails::Runner
- Inherits:
-
Object
- Object
- Guard::Rails::Runner
- 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_command ⇒ Object
- #environment ⇒ Object
-
#initialize(options) ⇒ Runner
constructor
A new instance of Runner.
- #pid ⇒ Object
- #pid_file ⇒ Object
- #restart ⇒ Object
- #sleep_time ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #wait_for_zeus ⇒ Object
Constructor Details
#initialize(options) ⇒ Runner
Returns a new instance of Runner.
10 11 12 13 |
# File 'lib/guard/rails/runner.rb', line 10 def initialize() @options = @root = [:root] ? File.([:root]) : Dir.pwd end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/guard/rails/runner.rb', line 8 def @options end |
Instance Method Details
#build_command ⇒ Object
45 46 47 48 49 50 |
# File 'lib/guard/rails/runner.rb', line 45 def build_command command = build_cli_command if [:CLI] command ||= build_zeus_command if [:zeus] command ||= build_rails_command "sh -c 'cd \"#{@root}\" && #{command} &'" end |
#environment ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/guard/rails/runner.rb', line 52 def environment rails_env = if [:zeus] nil else [:environment] end { "RAILS_ENV" => rails_env } end |
#pid ⇒ Object
66 67 68 |
# File 'lib/guard/rails/runner.rb', line 66 def pid has_pid? ? read_pid : nil end |
#pid_file ⇒ Object
62 63 64 |
# File 'lib/guard/rails/runner.rb', line 62 def pid_file @pid_file ||= File.([:pid_file] || File.join(@root, "tmp/pids/#{[:environment]}.pid")) end |
#restart ⇒ Object
40 41 42 43 |
# File 'lib/guard/rails/runner.rb', line 40 def restart stop start end |
#sleep_time ⇒ Object
70 71 72 |
# File 'lib/guard/rails/runner.rb', line 70 def sleep_time [:timeout].to_f / MAX_WAIT_COUNT.to_f end |
#start ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/guard/rails/runner.rb', line 15 def start kill_unmanaged_pid! if [:force_run] if [:zeus] && !wait_for_zeus UI.info "[Guard::Rails::Error] Could not find zeus socket file." return false end run_rails_command! wait_for_pid end |
#stop ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/guard/rails/runner.rb', line 27 def stop return unless has_pid? if (pid = read_pid) sig_sent = kill_process("INT", pid) wait_for_no_pid if sig_sent # If you lost your pid_file, you are already died. kill_process("KILL", pid) end remove_pid_file_and_wait_for_no_pid end |
#wait_for_zeus ⇒ Object
74 75 76 |
# File 'lib/guard/rails/runner.rb', line 74 def wait_for_zeus wait_for_loop { File.exist?(zeus_sockfile) } end |