Parent

Files

Guard::Runner

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

Public Class Methods

stopping_symbol_for(guard) click to toggle source

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_plugins

@param [Guard::Plugin] guard the Guard plugin to execute @return [Symbol] the symbol to catch

# File lib/guard/runner.rb, line 93
def self.stopping_symbol_for(guard)
  guard.group.options[:halt_on_fail] ? :no_catch : :task_has_failed
end

Public Instance Methods

run(task, scope = {}) click to toggle source

Runs a Guard-task on all registered plugins.

@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 19
def run(task, scope = {})
  Lumberjack.unit_of_work do
    _scoped_plugins(scope) do |guard|
      run_supervised_task(guard, task) if guard.respond_to?(task)
    end
  end
end
run_on_changes(modified, added, removed) click to toggle source

Runs the appropriate tasks on all registered plugins 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 38
def run_on_changes(modified, added, removed)
  ::Guard::UI.clearable
  _scoped_plugins 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_supervised_task(guard, task, *args) click to toggle source

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::Plugin] 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 63
def run_supervised_task(guard, task, *args)
  begin
    catch self.class.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.plugins.delete guard
    ::Guard::UI.info("\n#{ guard.class.name } has just been fired")

    ex
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.