Class: Guard::Guard
Overview
Base class that every Guard implementation must inherit from.
Guard will trigger the ‘start`, `stop`, `reload`, `run_all`, `run_on_change` and `run_on_deletion` task methods depending on user interaction and file modification.
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 I’ll be passed to the “_end” hook for further evaluation. You can throw ‘:task_has_failed` to indicate that your Guard method was not successful, and successive guard tasks will be aborted when the group has set the `:halt_on_fail` option.
Each Guard should provide a template Guardfile located within the Gem at ‘lib/guard/guard-name/templates/Guardfile`.
By default all watchers for a Guard are returning strings of paths to the Guard, but if your Guard want to allow any return value from a watcher, you can set the ‘any_return` option to true.
If one of those methods raise an exception other than ‘:task_has_failed`, the Guard::GuardName instance will be removed from the active guards.
Instance Attribute Summary collapse
-
#group ⇒ Object
Returns the value of attribute group.
-
#options ⇒ Object
Returns the value of attribute options.
-
#watchers ⇒ Object
Returns the value of attribute watchers.
Class Method Summary collapse
-
.init(name) ⇒ Object
Initialize the Guard.
Instance Method Summary collapse
-
#initialize(watchers = [], options = {}) ⇒ Guard
constructor
Initialize a Guard.
-
#reload ⇒ Object
Called when ‘reload|r|z + enter` is pressed.
-
#run_all ⇒ Object
Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…
-
#run_on_change(paths) ⇒ Object
Called on file(s) modifications that the Guard watches.
-
#run_on_deletion(paths) ⇒ Object
Called on file(s) deletions that the Guard watches.
-
#start ⇒ Object
Call once when Guard starts.
-
#stop ⇒ Object
Called when ‘stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
Methods included from Hook
add_callback, callbacks, has_callback?, included, notify, reset_callbacks!
Constructor Details
#initialize(watchers = [], options = {}) ⇒ Guard
Initialize a Guard.
48 49 50 51 |
# File 'lib/guard/guard.rb', line 48 def initialize(watchers = [], = {}) @group = [:group] ? .delete(:group).to_sym : :default @watchers, @options = watchers, end |
Instance Attribute Details
#group ⇒ Object
Returns the value of attribute group.
39 40 41 |
# File 'lib/guard/guard.rb', line 39 def group @group end |
#options ⇒ Object
Returns the value of attribute options.
39 40 41 |
# File 'lib/guard/guard.rb', line 39 def @options end |
#watchers ⇒ Object
Returns the value of attribute watchers.
39 40 41 |
# File 'lib/guard/guard.rb', line 39 def watchers @watchers end |
Class Method Details
.init(name) ⇒ Object
Initialize the Guard. This will copy the Guardfile template inside the Guard gem. The template Guardfile must be located within the Gem at ‘lib/guard/guard-name/templates/Guardfile`.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/guard/guard.rb', line 58 def self.init(name) if ::Guard::Dsl.guardfile_include?(name) ::Guard::UI.info "Guardfile already includes #{ name } guard" else content = File.read('Guardfile') guard = File.read("#{ ::Guard.locate_guard(name) }/lib/guard/#{ name }/templates/Guardfile") File.open('Guardfile', 'wb') do |f| f.puts(content) f.puts("") f.puts(guard) end ::Guard::UI.info "#{ name } guard added to Guardfile, feel free to edit it" end end |
Instance Method Details
#reload ⇒ Object
Called when ‘reload|r|z + enter` is pressed. This method should be mainly used for “reload” (really!) actions like reloading passenger/spork/bundler/…
97 98 |
# File 'lib/guard/guard.rb', line 97 def reload end |
#run_all ⇒ Object
Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…
106 107 |
# File 'lib/guard/guard.rb', line 106 def run_all end |
#run_on_change(paths) ⇒ Object
Called on file(s) modifications that the Guard watches.
115 116 |
# File 'lib/guard/guard.rb', line 115 def run_on_change(paths) end |
#run_on_deletion(paths) ⇒ Object
Called on file(s) deletions that the Guard watches.
124 125 |
# File 'lib/guard/guard.rb', line 124 def run_on_deletion(paths) end |
#start ⇒ Object
Call once when Guard starts. Please override initialize method to init stuff.
80 81 |
# File 'lib/guard/guard.rb', line 80 def start end |
#stop ⇒ Object
Called when ‘stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
88 89 |
# File 'lib/guard/guard.rb', line 88 def stop end |