class Guard::Runner


The runner is responsible for running all methods defined on each plugin.

def self.stopping_symbol_for(guard)

Returns:
  • (Symbol) - the symbol to catch

Parameters:
  • guard (Guard::Plugin) -- the Guard plugin to execute

Other tags:
    Note: - If a Guard group is being run and it has the `:halt_on_fail`
def self.stopping_symbol_for(guard)
  guard.group.options[:halt_on_fail] ? :no_catch : :task_has_failed
end

def _run_group_plugins(plugins)

def _run_group_plugins(plugins)
  failed_plugin = nil
  catch :task_has_failed do
    plugins.each do |plugin|
      failed_plugin = plugin
      yield plugin
      failed_plugin = nil
    end
  end
  UI.info format(PLUGIN_FAILED, failed_plugin.class.name) if failed_plugin
end

def _supervise(plugin, task, *args)

Raises:
  • (:task_has_failed) - when task has failed

Parameters:
  • args (Array) -- the arguments for the task
  • task (Symbol) -- the task to run
  • plugin (Guard::Plugin) -- guard the Guard to execute
def _supervise(plugin, task, *args)
  catch self.class.stopping_symbol_for(plugin) do
    plugin.hook("#{ task }_begin", *args)
    result = UI.options.with_progname(plugin.class.name) do
      begin
        plugin.send(task, *args)
      rescue Interrupt
        throw(:task_has_failed)
      end
    end
    plugin.hook("#{ task }_end", result)
    result
  end
rescue ScriptError, StandardError, RuntimeError
  UI.error("#{ plugin.class.name } failed to achieve its"\
                    " <#{ task }>, exception was:" \
                    "\n#{ $!.class }: #{ $!.message }" \
                    "\n#{ $!.backtrace.join("\n") }")
  Guard.state.session.plugins.remove(plugin)
  UI.info("\n#{ plugin.class.name } has just been fired")
  $!
end

def run(task, scope_hash = {})

Parameters:
  • scope_hash (Hash) -- either the Guard plugin or the group to run the task
  • task (Symbol) -- the task to run
def run(task, scope_hash = {})
  Lumberjack.unit_of_work do
    items = Guard.state.scope.grouped_plugins(scope_hash || {})
    items.each do |_group, plugins|
      _run_group_plugins(plugins) do |plugin|
        _supervise(plugin, task) if plugin.respond_to?(task)
      end
    end
  end
end

def run_on_changes(modified, added, removed)

Parameters:
  • removed (Array) -- the removed paths.
  • added (Array) -- the added paths.
  • modified (Array) -- the modified paths.
def run_on_changes(modified, added, removed)
  types = {
    MODIFICATION_TASKS => modified,
    ADDITION_TASKS => added,
    REMOVAL_TASKS => removed
  }
  UI.clearable
  Guard.state.scope.grouped_plugins.each do |_group, plugins|
    _run_group_plugins(plugins) do |plugin|
      UI.clear
      types.each do |tasks, unmatched_paths|
        next if unmatched_paths.empty?
        match_result = Watcher.match_files(plugin, unmatched_paths)
        next if match_result.empty?
        task = tasks.detect { |meth| plugin.respond_to?(meth) }
        _supervise(plugin, task, match_result) if task
      end
    end
  end
end