-
Notifications
You must be signed in to change notification settings - Fork 0
Create a guard
Creating a new Guard is very easy. For example, to create a Guard named yoyo just create a new gem by running bundle gem guard-yoyo. Please make your Guard start with guard-, so that it can easily be found on RubyGems.
$ bundle gem guard-yoyo
$ cd guard-yoyoNow extend the project structure to have an initial Guard:
.travis.yml # bonus point!
CHANGELOG.md # bonus point!
Gemfile
guard-yoyo.gemspec
Guardfile
lib/
guard/
yoyo/
templates/
Guardfile # needed for `guard init <guard-name>`
version.rb
yoyo.rb
test/ # or spec/
README.mdYour Guard main class Guard::Yoyo in lib/guard/guard-yoyo.rb must inherit from
Guard::Guard and should overwrite at least the
#run_on_change task methods.
Here is an example scaffold for lib/guard/yoyo.rb:
require 'guard'
require 'guard/guard'
module Guard
class Yoyo < Guard
# Initialize a Guard.
# @param [Array<Guard::Watcher>] watchers the Guard file watchers
# @param [Hash] options the custom Guard options
def initialize(watchers = [], options = {})
super
end
# Call once when Guard starts. Please override initialize method to init stuff.
# @raise [:task_has_failed] when start has failed
def start
end
# Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
# @raise [:task_has_failed] when stop has failed
def stop
end
# Called when `reload|r|z + enter` is pressed.
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
# @raise [:task_has_failed] when reload has failed
def reload
end
# Called when just `enter` is pressed
# This method should be principally used for long action like running all specs/tests/...
# @raise [:task_has_failed] when run_all has failed
def run_all
end
# Called on file(s) modifications that the Guard watches.
# @param [Array<String>] paths the changes files or paths
# @raise [:task_has_failed] when run_on_change has failed
def run_on_changes(paths)
end
# Called on file(s) deletions that the Guard watches.
# @param [Array<String>] paths the deleted files or paths
# @raise [:task_has_failed] when run_on_change has failed
def run_on_removals(paths)
end
end
endPlease take a look at the source code of some of the existing Guards for more concrete example and inspiration.
Alternatively, a new Guard can be added inline to a Guardfile with this basic structure:
require 'guard/guard'
module ::Guard
class InlineGuard < ::Guard::Guard
def run_all
end
def run_on_changes(paths)
end
end
end@avdi has a very cool inline Guard example in his blog post A Guardfile for Redis.
This wiki and the Guard README document contains a lot of information, please take your time and read these instructions carefully.
If you run into any trouble, you may start by understanding how Guard works.
We provide detailed changes for each Guard release.
Be sure to read the CONTRIBUTING guidelines before reporting a new Guard issue or open a pull request.
If you have any questions about the Guard usage or want to share some information with the Guard community, please go to one of the following places:
- Google+ community
- Google group
- StackOverflow
- IRC channel
#guard(irc.freenode.net) for chatting
Intro
Installation
- System Notifications
- Terminal Colors on Windows
- Add Readline support to Ruby on Mac OS X
- Which Growl library should I use
- Efficient Filesystem Handling
Getting Started
- List of Guard Commands
- Command Line Options for Guard
- List of available Guards
- Guardfile examples
- Run Guard within RubyMine
- Guardfile-DSL / Configuring-Guard
- Configuration Files
- Interacting with Guard
- Guard Signals
Troubleshooting
Advanced use of Guard
Cookbooks
Development