-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utilização do guard para execução de tarefas automáticas #201
- Loading branch information
1 parent
8081763
commit 2394b38
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
ERB_TEMPLATE = <<~HEREDOC | ||
guard :shell do | ||
<% all_tasks.each do |t, files| %> | ||
watch(%r{^(<%= files.join('|') %>)$}) do |m| | ||
system("rake <%= t %>") | ||
end | ||
<% end %> | ||
end | ||
HEREDOC | ||
|
||
desc "Generates a Guardfile from Rake tasks" | ||
task :guard do | ||
app = Rake::application | ||
app.init | ||
app.load_rakefile | ||
|
||
all_tasks = {} | ||
app.tasks.each do |t| | ||
t.sources.each do |src| | ||
if File.file?(src) then | ||
all_tasks[t.name] = [] unless all_tasks[t.name] | ||
all_tasks[t.name] << src | ||
end | ||
end | ||
end | ||
template = ERB.new(ERB_TEMPLATE) | ||
File.write('Guardfile', template.result(binding)) | ||
end |