Skip to content

Commit

Permalink
Utilização do guard para execução de tarefas automáticas #201
Browse files Browse the repository at this point in the history
  • Loading branch information
edusantana committed Jun 16, 2020
1 parent 8081763 commit 2394b38
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions limarka.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ Gem::Specification.new do |spec|
spec.add_dependency "pandoc_abnt", "~> 2.0.0"
spec.add_dependency "guard"
spec.add_dependency "guard-shell"
spec.add_dependency "guard-rake"

end
28 changes: 28 additions & 0 deletions rakelib/guard.rake
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

0 comments on commit 2394b38

Please sign in to comment.