2011-05-27 18:41:07 +00:00
require 'guard'
require 'guard/guard'
2011-06-01 14:06:35 +00:00
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
2011-06-01 14:06:35 +00:00
attr_reader :options , :runner
2011-05-27 18:41:07 +00:00
2011-06-03 13:18:16 +00:00
DEFAULT_OPTIONS = {
2011-05-31 20:15:19 +00:00
:port = > 3000 ,
:environment = > 'development' ,
:start_on_start = > true ,
2011-06-01 14:42:53 +00:00
:force_run = > false ,
2012-01-14 03:51:56 +00:00
:timeout = > 30 ,
2011-08-25 14:26:04 +00:00
:server = > nil ,
2011-08-25 14:53:20 +00:00
:debugger = > false
2011-06-03 13:18:16 +00:00
}
def initialize ( watchers = [ ] , options = { } )
super
@options = DEFAULT_OPTIONS . merge ( options )
2011-06-01 14:06:35 +00:00
2011-06-01 14:36:12 +00:00
@runner = RailsRunner . new ( @options )
2011-05-27 18:41:07 +00:00
end
def start
2011-07-12 12:59:26 +00:00
server = options [ :server ] ? " #{ options [ :server ] } and " : " "
UI . info " Guard::Rails will now restart your app on port #{ options [ :port ] } using #{ server } #{ options [ :environment ] } environment. "
2012-01-14 03:42:57 +00:00
reload ( " start " ) if options [ :start_on_start ]
2011-05-27 18:41:07 +00:00
end
2012-01-14 03:42:57 +00:00
def reload ( action = " restart " )
action_cap = action . capitalize
UI . info " #{ action_cap } ing Rails... "
Notifier . notify ( " Rails #{ action } ing on port #{ options [ :port ] } in #{ options [ :environment ] } environment... " , :title = > " #{ action_cap } ing Rails... " , :image = > :pending )
2011-06-01 14:28:32 +00:00
if runner . restart
2012-01-14 03:42:57 +00:00
UI . info " Rails #{ action } ed, pid #{ runner . pid } "
Notifier . notify ( " Rails #{ action } ed on port #{ options [ :port ] } . " , :title = > " Rails #{ action } ed! " , :image = > :success )
2011-06-01 14:28:32 +00:00
else
2012-01-14 03:42:57 +00:00
UI . info " Rails NOT #{ action } ed, check your log files. "
Notifier . notify ( " Rails NOT #{ action } ed, check your log files. " , :title = > " Rails NOT #{ action } ed! " , :image = > :failed )
2011-06-01 14:28:32 +00:00
end
2011-05-27 18:58:20 +00:00
end
def stop
Notifier . notify ( " Until next time... " , :title = > " Rails shutting down. " , :image = > :pending )
2011-06-01 14:06:35 +00:00
runner . stop
2011-05-27 18:41:07 +00:00
end
2012-06-12 17:45:03 +00:00
def run_on_changes ( paths )
2011-10-17 03:33:27 +00:00
reload
2011-05-27 18:41:07 +00:00
end
2012-06-12 17:45:57 +00:00
alias :run_on_change :run_on_changes
2011-05-27 18:41:07 +00:00
end
end