Class: Guard::Plugin

  • Object
show all
Defined in:


Base class from which every Guard plugin implementation must inherit.

Guard will trigger the Base#start, Base#stop, Base#reload, Base#run_all and Base#run_on_changes (Base#run_on_additions, Base#run_on_modifications and Base#run_on_removals) task methods depending on user interaction and file modification.

Base#run_on_changes could be implemented to handle all the changes task case (additions, modifications, removals) in once, or each task can be implemented separately with a specific behavior.

In each of these Guard task methods you have to implement some work when you want to support this kind of task. The return value of each Guard task method is not evaluated by Guard, but it'll be passed to the “_end” hook for further evaluation. You can throw `:task_has_failed` to indicate that your Guard plugin method was not successful, and successive Guard plugin tasks will be aborted when the group has set the `:halt_on_fail` option.

Each Guard plugin should provide a template Guardfile located within the Gem at `lib/guard/guard-name/templates/Guardfile`.

Watchers for a Guard plugin should return a file path or an array of files paths to Guard, but if your Guard plugin wants to allow any return value from a watcher, you can set the `any_return` option to true.

If one of those methods raises an exception other than `:task_has_failed`, the `Guard::GuardName` instance will be removed from the active Guard plugins.


Throw :task_has_failed

def run_all
  if !['all'])
    throw :task_has_failed

See Also:

Defined Under Namespace

Modules: Base, Hooker

Instance Attribute Summary

Attributes included from Base

#callbacks, #group, #options, #watchers

Instance Method Summary collapse

Methods included from Base

included, #name, #reload, #run_all, #run_on_additions, #run_on_changes, #run_on_modifications, #run_on_removals, #start, #stop, #title, #to_s

Methods included from Hooker

add_callback, callbacks, #hook, notify, reset_callbacks!

Constructor Details

#initialize(options = {}) ⇒ Plugin

Initializes a Guard plugin. Don't do any work here, especially as Guard plugins get initialized even if they are not in an active group!

Options Hash (options):

  • watchers (Array<Guard::Watcher>)

    the Guard plugin file watchers

  • group (Symbol)

    the group this Guard plugin belongs to

  • any_return (Boolean)

    allow any object to be returned from a watcher

# File 'lib/guard/plugin.rb', line 60

def initialize(options = {})