guard-rails/lib/guard/rails.rb

46 lines
1.2 KiB
Ruby
Raw Normal View History

2011-05-27 18:41:07 +00:00
require 'guard'
require 'guard/guard'
require 'guard/rails/runner'
2011-05-31 20:15:19 +00:00
require 'rbconfig'
2011-05-27 18:41:07 +00:00
module Guard
class Rails < ::Guard::Guard
attr_reader :options, :runner
2011-05-27 18:41:07 +00:00
def initialize(watchers = [], options = {})
2011-05-27 18:51:49 +00:00
super
2011-05-31 20:15:19 +00:00
@options = {
:port => 3000,
:environment => 'development',
:start_on_start => true,
:force_run => false
}.merge(options)
@runner = RailsRunner.new(options)
2011-05-27 18:41:07 +00:00
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
UI.info "Restarting Rails"
2011-05-27 19:59:48 +00:00
Notifier.notify("Rails restarting on port #{options[:port]} in #{options[:environment]} environment...", :title => "Restarting Rails...", :image => :pending)
runner.restart
UI.info "Rails restarted, pid #{File.read(pid_file)}"
2011-05-27 19:59:48 +00:00
Notifier.notify("Rails restarted on port #{options[:port]}.", :title => "Rails restarted!", :image => :success)
2011-05-27 18:58:20 +00:00
end
def stop
Notifier.notify("Until next time...", :title => "Rails shutting down.", :image => :pending)
runner.stop
2011-05-27 18:41:07 +00:00
end
def run_on_change(paths)
run_all
end
end
end