2010-10-03 21:00:33 +00:00
|
|
|
module Guard
|
|
|
|
class Dsl
|
2010-12-17 15:31:39 +00:00
|
|
|
|
|
|
|
class << self
|
|
|
|
def evaluate_guardfile(options = {})
|
2010-12-17 17:13:31 +00:00
|
|
|
@@options = options
|
2010-12-17 17:37:24 +00:00
|
|
|
|
2010-12-17 17:44:12 +00:00
|
|
|
if File.exists?(guardfile_path)
|
2010-12-17 15:31:39 +00:00
|
|
|
begin
|
2010-12-17 17:44:12 +00:00
|
|
|
new.instance_eval(File.read(guardfile_path), guardfile_path, 1)
|
2010-12-17 15:31:39 +00:00
|
|
|
rescue
|
|
|
|
UI.error "Invalid Guardfile, original error is:\n#{$!}"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
else
|
2011-05-24 21:32:02 +00:00
|
|
|
UI.error "No Guardfile found, please create one."
|
2010-10-30 16:26:09 +00:00
|
|
|
exit 1
|
|
|
|
end
|
2010-12-17 15:31:39 +00:00
|
|
|
end
|
|
|
|
|
2010-12-17 17:37:24 +00:00
|
|
|
def guardfile_include?(guard_name)
|
2010-12-17 17:44:12 +00:00
|
|
|
File.read(guardfile_path).match(/^guard\s*\(?\s*['":]#{guard_name}['"]?/)
|
|
|
|
end
|
|
|
|
|
|
|
|
def guardfile_path
|
2011-05-25 18:23:02 +00:00
|
|
|
File.exist?(local_guardfile_path) ? local_guardfile_path : home_guardfile_path
|
2011-05-24 21:32:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def local_guardfile_path
|
|
|
|
File.join(Dir.pwd, "Guardfile")
|
|
|
|
end
|
|
|
|
|
|
|
|
def home_guardfile_path
|
2011-05-25 18:23:02 +00:00
|
|
|
File.expand_path(File.join("~", "Guardfile"))
|
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
|