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_command ⇒ Object
- #environment ⇒ 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 12 |
# File 'lib/guard/rails/runner.rb', line 9 def initialize() @options = @root = [:root] ? File.([:root]) : Dir.pwd 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_command ⇒ Object
37 38 39 40 41 42 |
# File 'lib/guard/rails/runner.rb', line 37 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
44 45 46 47 48 49 50 51 52 |
# File 'lib/guard/rails/runner.rb', line 44 def environment rails_env = if [:zeus] nil else [:environment] end { "RAILS_ENV" => rails_env } end |
#pid ⇒ Object
58 59 60 |
# File 'lib/guard/rails/runner.rb', line 58 def pid File.file?(pid_file) ? File.read(pid_file).to_i : nil end |
#pid_file ⇒ Object
54 55 56 |
# File 'lib/guard/rails/runner.rb', line 54 def pid_file File.([:pid_file] || File.join(@root, "tmp/pids/#{[:environment]}.pid")) end |
#restart ⇒ Object
32 33 34 35 |
# File 'lib/guard/rails/runner.rb', line 32 def restart stop start end |
#sleep_time ⇒ Object
62 63 64 |
# File 'lib/guard/rails/runner.rb', line 62 def sleep_time [:timeout].to_f / MAX_WAIT_COUNT.to_f end |
#start ⇒ Object
14 15 16 17 18 |
# File 'lib/guard/rails/runner.rb', line 14 def start kill_unmanaged_pid! if [:force_run] run_rails_command! wait_for_pid end |
#stop ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/guard/rails/runner.rb', line 20 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 |