Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple ruby guard watcher

Tags:

ruby

gem

guard

Is there a way to create a simple guard watch? I want to run a rake task when a file changes in a specific directory and going through all of these steps is too much for this one off task. https://github.com/guard/guard/wiki/Create-a-guard

I tried adding this in the Guardfile but it doesn't work.

guard :doc do
  watch(%r{^documentation})                       { "rake doc:build" }
end

watch("/documentation")                       { "rake doc:build" }

So do you know of a simple way to run a rake task when a file is updated with guard?

like image 763
jspooner Avatar asked Jun 28 '12 21:06

jspooner


People also ask

What does guard gem do?

Guard is a command line tool to easily handle events on file system modifications.

What is Guardfile?

A guard file is another level of security that defines the access rights of various users and programs for access to a program, data file, or database. A guard file can contain one or more access rules. These access rules apply to the file that the guard file is assigned to protect.


1 Answers

The most straightforward way is to use guard-rake to run a Rake task on a file modification.

A more generic solution is to use guard-shell to run any command line tool on a file modification.

More complex use cases should be solved by creating your own guard plugin. You don't even need to create a gem, since you can simply define them as inline guard as Avdi shows us in his a Guardfile for Redis blog post.

When you want to share your Guard, just have a look at more advanced Guard plugins like guard-rspec or guard-jasmine as examples.

like image 196
Netzpirat Avatar answered Sep 19 '22 17:09

Netzpirat