2010-10-03 21:00:33 +00:00
|
|
|
module Guard
|
|
|
|
class Dsl
|
2010-12-17 15:31:39 +00:00
|
|
|
|
|
|
|
class << self
|
|
|
|
attr_accessor :options
|
|
|
|
|
|
|
|
def evaluate_guardfile(options = {})
|
2010-12-17 17:13:31 +00:00
|
|
|
@@options = options
|
2010-12-17 15:31:39 +00:00
|
|
|
|
|
|
|
guardfile = "#{Dir.pwd}/Guardfile"
|
|
|
|
if File.exists?(guardfile)
|
|
|
|
begin
|
|
|
|
new.instance_eval(File.read(guardfile.to_s), guardfile.to_s, 1)
|
|
|
|
rescue
|
|
|
|
UI.error "Invalid Guardfile, original error is:\n#{$!}"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
else
|
|
|
|
UI.error "No Guardfile in current folder, please create one."
|
2010-10-30 16:26:09 +00:00
|
|
|
exit 1
|
|
|
|
end
|
2010-12-17 15:31:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def guardfile_included?(guard_name)
|
|
|
|
File.read('Guardfile').include?("guard '#{guard_name}'")
|
2010-10-30 16:26:09 +00:00
|
|
|
end
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2010-12-17 15:31:39 +00:00
|
|
|
|
2010-12-17 17:13:31 +00:00
|
|
|
def group(name, &guard_definition)
|
|
|
|
guard_definition.call if guard_definition && (@@options[:group].empty? || @@options[:group].include?(name))
|
2010-10-07 20:37:30 +00:00
|
|
|
end
|
2010-12-17 15:31:39 +00:00
|
|
|
|
2010-12-17 17:13:31 +00:00
|
|
|
def guard(name, options = {}, &watch_definition)
|
2010-10-03 21:00:33 +00:00
|
|
|
@watchers = []
|
2010-12-17 17:13:31 +00:00
|
|
|
watch_definition.call if watch_definition
|
2010-10-07 20:37:30 +00:00
|
|
|
::Guard.add_guard(name, @watchers, options)
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2010-12-17 17:13:31 +00:00
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
def watch(pattern, &action)
|
2010-10-07 20:37:30 +00:00
|
|
|
@watchers << ::Guard::Watcher.new(pattern, action)
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2010-12-17 17:13:31 +00:00
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
|
|
|
end
|