2011-05-27 18:41:07 +00:00
|
|
|
require 'guard'
|
|
|
|
require 'guard/guard'
|
|
|
|
|
|
|
|
module Guard
|
|
|
|
class Rails < ::Guard::Guard
|
|
|
|
attr_reader :options
|
|
|
|
|
|
|
|
def initialize(watchers = [], options = {})
|
2011-05-27 18:51:49 +00:00
|
|
|
super
|
2011-05-27 18:41:07 +00:00
|
|
|
@options = { :port => 3000, :environment => 'development', :start_on_start => true }.merge(options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def start
|
|
|
|
UI.info "Guard::Rails restarting app on port #{options[:port]} using #{options[:environment]} environment."
|
|
|
|
run_all if options[:start_on_start]
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_all
|
|
|
|
Notifier.notify("Rails restarting on port #{options[:port]} in #{options[:environment]}", :title => "Restarting Rails...", :image => :pending)
|
|
|
|
system %{sh -c '[[ -f tmp/pids/#{options[:environment]}.pid ]] && kill $(cat tmp/pids/#{options[:environment]}.pid)'}
|
2011-05-27 18:51:49 +00:00
|
|
|
system %{rails s -d -e #{options[:environment]} -p #{options[:port]}}
|
2011-05-27 18:41:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run_on_change(paths)
|
|
|
|
run_all
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|