- Notifications
You must be signed in to change notification settings - Fork32
guard-rake runs a rake task when files change
License
rubyist/guard-rake
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Guard::Rake allows you to automatically run a Rake task when files aremodified.
Please be sure to haveGuard installedbefore continuing.
Install the gem:
$ gem install guard-rake
Add it to yourGemfile
gem'guard-rake'
Add the default Guard::Rake template to yourGuardfile
by running thiscommand:
$ guard init rake
Please read theGuard usage documentation.
Guard::Rake comes with a default template that looks like this:
guard'rake',:task=>'doit'dowatch(%r{^some_files/.+$})end
This will run the rake taskdoit
from yourRakefile
whenever any ofthe watched files change.
:task=>'doit'# name of the task to be executed, required:run_on_all=>false# runs when the 'run_all' signal is received from Guard (enter is pressed), default: true:run_on_start=>true# runs when guard is started, default: true:task_args=>[]# arguments to pass to Rake::Task#invoke, default: []
By default, the changed file paths will be passed into the rake task. Example:
task:doit,:pathsdo |t,args|args.paths# Will contain an array of changed pathsend
You may also use this in conjunction with the :task_args options. Anything in :task_args willbe passed in first, then the array of changed paths. Example:
# Guardfileguard'rake',:task=>'doit',:task_args=>['a','b']dowatch(%r{^some_files/.+$})end# Rakefiletask:doit,[:first,:second,:paths]do |t,args|args.first# "a"args.second# "b"args.paths# ['changed1.rb', 'changed2.rb']end
This second usage will describe how to create a rake task that generates Guardfile from rake tasks.
First, add this to your Gemfile:
gem'guard-rake'gem'guard-shell'
You will need some tasks with file dependencies in your Rakefile. I'f you don't have those, try put this code in your Rakefile:
files=Rake::FileList.new('*.md')desc"Create a book"task'book'=>filesdosh"cat#{files.join(" ")} > book.txt"end
Now you are ready to import our rake task, put Inside yourRakefile
:
require"guard/rake/task"Guard::Rake::Task.new
You can see you have two new tasks:
$ rake -Trake book # Create a bookrake guard # Create Guardfile from rake tasks
And the book task have these dependencies:
$ rake -Prake book README.mdrake guard
If you call theguard
task it will createGuardfile
:
$ rake guard$ cat Guardfileguard :shell do watch(%r{^(README.md)$}) do |m| system("rake book") endend
You can also add theRakefile
dependency:
task :guard => ['Rakefile']
And using theguard
task it will produce thisGuardfile
:
guard:shelldowatch(%r{^(README.md)$})do |m|system("rake book")endwatch(%r{^(Rakefile)$})do |m|system("rake guard")endend
If you want update yourGuardfile
with other content, it's best to create your own ERB template:
Guard::Rake::Task.newdo |t|t.template=File.read('Guardfile.erb')end
And then create yourGuardfile.erb
as a template:
guard:shelldo <% all_tasks.each do |t, files| %> watch(%r{^(<%= files.join('|') %>)$}) do |m| system("rake <%= t %>") end <% end %> <%# Add your custom code here %>end<%# Or here %>
- Source hosted atGitHub
- Report issues and feature requests toGitHub Issues
Pull requests welcome!
(The MIT License)
Copyright (c) 2011 Scott Barron
Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the'Software'), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:
The above copyright notice and this permission notice shall beincluded in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANYCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
About
guard-rake runs a rake task when files change
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors15
Uh oh!
There was an error while loading.Please reload this page.