Class: Guard::Foreman
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::Foreman
- Defined in:
- lib/guard/foreman.rb
Constant Summary collapse
- DEFAULT_LOG_LOCATION =
Default log location (Rails in mind)
"log/foreman.log"
- TITLE =
"Foreman status"
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Foreman
constructor
Initialize a Guard.
-
#reload ⇒ Object
Called when ‘reload|r|z + enter` is pressed.
-
#run_all ⇒ Object
Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…
- #run_on_additions(paths) ⇒ Object
-
#run_on_changes(paths) ⇒ Object
Called on file(s) modifications that the Guard watches.
- #run_on_modifications(paths) ⇒ Object
- #run_on_removals(paths) ⇒ Object
-
#start ⇒ Object
Call once when Guard starts.
-
#stop ⇒ Object
Called when ‘stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
Constructor Details
#initialize(options = {}) ⇒ Foreman
Initialize a Guard.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/guard/foreman.rb', line 15 def initialize( = {}) @log_file = .fetch(:log_file, DEFAULT_LOG_LOCATION) @concurrency = [:concurrency] @env = [:env] @procfile = [:procfile] @port = [:port] @root = [:root] super end |
Instance Method Details
#reload ⇒ Object
Called when ‘reload|r|z + enter` is pressed. This method should be mainly used for “reload” (really!) actions like reloading passenger/spork/bundler/…
70 71 72 73 74 |
# File 'lib/guard/foreman.rb', line 70 def reload info "Restarting Foreman..." stop start end |
#run_all ⇒ Object
Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…
79 80 81 |
# File 'lib/guard/foreman.rb', line 79 def run_all start end |
#run_on_additions(paths) ⇒ Object
90 91 92 |
# File 'lib/guard/foreman.rb', line 90 def run_on_additions(paths) reload end |
#run_on_changes(paths) ⇒ Object
Called on file(s) modifications that the Guard watches.
86 87 88 |
# File 'lib/guard/foreman.rb', line 86 def run_on_changes(paths) reload end |
#run_on_modifications(paths) ⇒ Object
94 95 96 |
# File 'lib/guard/foreman.rb', line 94 def run_on_modifications(paths) reload end |
#run_on_removals(paths) ⇒ Object
98 99 100 |
# File 'lib/guard/foreman.rb', line 98 def run_on_removals(paths) reload end |
#start ⇒ Object
Call once when Guard starts. Please override initialize method to init stuff.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/guard/foreman.rb', line 28 def start # Stop if running stop if @pid cmd = "foreman start" cmd += " -c #{@concurrency}" if @concurrency cmd += " -e #{@env}" if @env cmd += " -f #{@procfile}" if @procfile cmd += " -p #{@port}" if @port cmd += " -d #{@root}" if @root #cmd += " > #{@log_file}" # Disabled for now debug "About to run #{cmd}" @pid = ::Spoon.spawnp(*cmd.split(" ")) # Spoon is a little weird info "Foreman started." debug "Foreman has pid #{@pid}" success "Foreman started" end |
#stop ⇒ Object
Called when ‘stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/guard/foreman.rb', line 50 def stop if @pid begin debug "Asking Foreman to terminate... (#{@pid})" ::Process.kill("TERM", @pid) debug "Waiting for Foreman to stop..." ::Process.waitpid(@pid) @pid = nil # Unset @pid rescue Errno::ESRCH # Don't do anything, the process does not exist debug "Could not find Foreman process" end info "Foreman stopped." end end |