Initial yardoc for the main Guard class for specific implementations.

This commit is contained in:
Michael Kessler 2011-09-20 12:07:34 +02:00
parent dc009d445a
commit 0f5b2b764a

View File

@ -1,21 +1,39 @@
module Guard module Guard
# Main class that every Guard implementation must subclass.
#
# Guard will trigger the `start`, `stop`, `reload`, `run_all` and `run_on_change`
# methods depending on user interaction and file modification.
#
# Each Guard should provide a template Guardfile located within the Gem
# at `lib/guard/guard-name/templates/Guardfile`.
#
class Guard class Guard
include Hook include Hook
attr_accessor :watchers, :options, :group attr_accessor :watchers, :options, :group
# initialize a Guard.
#
# @param [Array<Guard::Watcher>] watchers the Guard file watchers
# @param [Hash] options the custom Guard options.
#
def initialize(watchers = [], options = {}) def initialize(watchers = [], options = {})
@group = options.delete(:group) || :default @group = options.delete(:group) || :default
@watchers, @options = watchers, options @watchers, @options = watchers, options
end end
# Guardfile template needed inside guard gem # 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`.
#
# @param [String] name the name of the Guard
#
def self.init(name) def self.init(name)
if ::Guard::Dsl.guardfile_include?(name) if ::Guard::Dsl.guardfile_include?(name)
::Guard::UI.info "Guardfile already includes #{name} guard" ::Guard::UI.info "Guardfile already includes #{ name } guard"
else else
content = File.read('Guardfile') content = File.read('Guardfile')
guard = File.read("#{::Guard.locate_guard(name)}/lib/guard/#{name}/templates/Guardfile") guard = File.read("#{ ::Guard.locate_guard(name) }/lib/guard/#{ name }/templates/Guardfile")
File.open('Guardfile', 'wb') do |f| File.open('Guardfile', 'wb') do |f|
f.puts(content) f.puts(content)
f.puts("") f.puts("")
@ -25,31 +43,43 @@ module Guard
end end
end end
# ================ # Call once when guard starts. Please override initialize method to init stuff.
# = Guard method = #
# ================ # @return [Boolean] Whether the start action was successful or not
#
# Call once when guard starts
# Please override initialize method to init stuff
def start def start
true true
end end
# Call once when guard quit # Call once when guard quit.
#
# @return [Boolean] Whether the stop action was successful or not
#
def stop def stop
true true
end end
# Should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/... # Should be used for "reload" (really!) actions like reloading passenger/spork/bundler/...
#
# @return [Boolean] Whether the reload action was successful or not
#
def reload def reload
true true
end end
# Should be principally used for long action like running all specs/tests/... # Should be used for long action like running all specs/tests/...
#
# @return [Boolean] Whether the run_all action was successful or not
#
def run_all def run_all
true true
end end
# Will be triggered when a file change matched a watcher.
#
# @param [Array<String>] paths the changes files or paths
# @return [Boolean] Whether the run_all action was successful or not
#
def run_on_change(paths) def run_on_change(paths)
true true
end end