2010-10-03 21:00:33 +00:00
|
|
|
module Guard
|
|
|
|
class Guard
|
2011-04-14 20:53:53 +00:00
|
|
|
include Hook
|
2011-04-16 21:13:29 +00:00
|
|
|
|
2011-08-16 22:36:02 +00:00
|
|
|
attr_accessor :watchers, :options, :group
|
2011-01-19 22:05:45 +00:00
|
|
|
|
2011-08-17 08:04:42 +00:00
|
|
|
def initialize(watchers = [], options = {})
|
|
|
|
@group = options.delete(:group) || :default
|
2010-10-03 21:00:33 +00:00
|
|
|
@watchers, @options = watchers, options
|
|
|
|
end
|
2011-01-19 22:05:45 +00:00
|
|
|
|
2010-10-07 20:37:30 +00:00
|
|
|
# Guardfile template needed inside guard gem
|
|
|
|
def self.init(name)
|
2010-12-17 17:37:24 +00:00
|
|
|
if ::Guard::Dsl.guardfile_include?(name)
|
2011-08-02 10:03:15 +00:00
|
|
|
::Guard::UI.info "Guardfile already includes #{name} guard"
|
2010-10-07 20:37:30 +00:00
|
|
|
else
|
|
|
|
content = File.read('Guardfile')
|
|
|
|
guard = File.read("#{::Guard.locate_guard(name)}/lib/guard/#{name}/templates/Guardfile")
|
|
|
|
File.open('Guardfile', 'wb') do |f|
|
2010-11-25 23:58:36 +00:00
|
|
|
f.puts(content)
|
|
|
|
f.puts("")
|
|
|
|
f.puts(guard)
|
2010-10-07 20:37:30 +00:00
|
|
|
end
|
|
|
|
::Guard::UI.info "#{name} guard added to Guardfile, feel free to edit it"
|
|
|
|
end
|
|
|
|
end
|
2011-01-19 22:05:45 +00:00
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
# ================
|
|
|
|
# = Guard method =
|
|
|
|
# ================
|
2011-01-19 22:05:45 +00:00
|
|
|
|
2010-10-27 20:14:21 +00:00
|
|
|
# Call once when guard starts
|
|
|
|
# Please override initialize method to init stuff
|
2010-10-03 21:00:33 +00:00
|
|
|
def start
|
|
|
|
true
|
|
|
|
end
|
2011-01-19 22:05:45 +00:00
|
|
|
|
2010-10-27 20:14:21 +00:00
|
|
|
# Call once when guard quit
|
2010-10-03 21:00:33 +00:00
|
|
|
def stop
|
|
|
|
true
|
|
|
|
end
|
2011-01-19 22:05:45 +00:00
|
|
|
|
2010-10-27 20:14:21 +00:00
|
|
|
# Should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
|
2010-10-03 21:00:33 +00:00
|
|
|
def reload
|
|
|
|
true
|
|
|
|
end
|
2011-01-19 22:05:45 +00:00
|
|
|
|
2010-10-27 20:14:21 +00:00
|
|
|
# Should be principally used for long action like running all specs/tests/...
|
2010-10-03 21:00:33 +00:00
|
|
|
def run_all
|
|
|
|
true
|
|
|
|
end
|
2011-01-19 22:05:45 +00:00
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
def run_on_change(paths)
|
|
|
|
true
|
|
|
|
end
|
2011-01-19 22:05:45 +00:00
|
|
|
|
2011-08-23 16:07:23 +00:00
|
|
|
def run_on_deletion(paths)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2011-08-19 20:53:48 +00:00
|
|
|
end
|