Object
The runner is responsible for running all methods defined on each guards.
Deprecation message for the `run_on_change` method
Deprecation message for the `run_on_deletion` method
Returns the symbol that has to be caught when running a supervised task.
@note If a Guard group is being run and it has the `:halt_on_fail`
option set, this method returns :no_catch as it will be caught at the group level.
@see .scoped_guards
@param [Guard::Guard] guard the Guard plugin to execute @return [Symbol] the symbol to catch
# File lib/guard/runner.rb, line 125 def self.stopping_symbol_for(guard) return :task_has_failed if guard.group.class != Symbol group = ::Guard.groups(guard.group) group.options.fetch(:halt_on_fail, false) ? :no_catch : :task_has_failed end
Displays a warning for each deprecated-method used is any registered guard.
# File lib/guard/runner.rb, line 37 def deprecation_warning ::Guard.guards.each do |guard| ::Guard::UI.deprecation(RUN_ON_CHANGE_DEPRECATION % guard.class.name) if guard.respond_to?(:run_on_change) ::Guard::UI.deprecation(RUN_ON_DELETION_DEPRECATION % guard.class.name) if guard.respond_to?(:run_on_deletion) end end
Runs a Guard-task on all registered guards.
@param [Symbol] task the task to run @param [Hash] scopes either the Guard plugin or the group to run the task on
@see self.run_supervised_task
# File lib/guard/runner.rb, line 51 def run(task, scopes = {}) Lumberjack.unit_of_work do scoped_guards(scopes) do |guard| run_supervised_task(guard, task) if guard.respond_to?(task) end end end
Runs the appropriate tasks on all registered guards based on the passed changes.
@param [Array<String>] modified the modified paths. @param [Array<String>] added the added paths. @param [Array<String>] removed the removed paths.
# File lib/guard/runner.rb, line 70 def run_on_changes(modified, added, removed) ::Guard::UI.clearable scoped_guards do |guard| modified_paths = ::Guard::Watcher.match_files(guard, modified) added_paths = ::Guard::Watcher.match_files(guard, added) removed_paths = ::Guard::Watcher.match_files(guard, removed) ::Guard::UI.clear if clearable?(guard, modified_paths, added_paths, removed_paths) run_first_task_found(guard, MODIFICATION_TASKS, modified_paths) unless modified_paths.empty? run_first_task_found(guard, ADDITION_TASKS, added_paths) unless added_paths.empty? run_first_task_found(guard, REMOVAL_TASKS, removed_paths) unless removed_paths.empty? end end
Run a Guard plugin task, but remove the Guard plugin when his work leads to a system failure.
When the Group has `:halt_on_fail` disabled, we've to catch `:task_has_failed` here in order to avoid an uncaught throw error.
@param [Guard::Guard] guard the Guard to execute @param [Symbol] task the task to run @param [Array] args the arguments for the task @raise [:task_has_failed] when task has failed
# File lib/guard/runner.rb, line 95 def run_supervised_task(guard, task, *args) begin catch Runner.stopping_symbol_for(guard) do guard.hook("#{ task }_begin", *args) result = guard.send(task, *args) guard.hook("#{ task }_end", result) result end rescue Exception => ex ::Guard::UI.error("#{ guard.class.name } failed to achieve its <#{ task.to_s }>, exception was:" + "\n#{ ex.class }: #{ ex.message }\n#{ ex.backtrace.join("\n") }") ::Guard.guards.delete guard ::Guard::UI.info("\n#{ guard.class.name } has just been fired") ex end end
Generated with the Darkfish Rdoc Generator 2.