Class: Guard::Exec

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/exec.rb,
lib/guard/exec/runner.rb,
lib/guard/exec/options.rb

Defined Under Namespace

Modules: Options Classes: MissingCommandOption, Runner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Exec

Initializes a Guard plugin. Don’t do any work here, especially as Guard plugins get initialized even if they are not in an active group!

Parameters:

  • options (Hash) (defaults to: {})

    the custom Guard plugin options

Options Hash (options):

  • watchers (Array<Guard::Watcher>)

    the Guard plugin file watchers

  • group (Symbol)

    the group this Guard plugin belongs to

  • any_return (Boolean)

    allow any object to be returned from a watcher

Raises:



18
19
20
21
22
23
24
25
# File 'lib/guard/exec.rb', line 18

def initialize(options = {})
  raise MissingCommandOption unless options[:command]

  super

  @options = Options.with_defaults(options)
  @runner = Runner.new(@options)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/guard/exec.rb', line 9

def options
  @options
end

#runnerObject

Returns the value of attribute runner.



9
10
11
# File 'lib/guard/exec.rb', line 9

def runner
  @runner
end

Instance Method Details

#reloadObject

Called when ‘reload|r|z + enter` is pressed. This method should be mainly used for “reload” (really!) actions like reloading passenger/spork/bundler/…

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when reload has failed



49
50
# File 'lib/guard/exec.rb', line 49

def reload
end

#run_allObject

Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when run_all has failed



58
59
60
61
62
# File 'lib/guard/exec.rb', line 58

def run_all
  Compat::UI.info ['Running all', options[:name]].compact.join ' '

  runner.run
end

#run_on_additions(paths) ⇒ Object

Called on file(s) additions that the Guard plugin watches.

Parameters:

  • paths (Array<String>)

    the changes files or paths

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when run_on_additions has failed



70
71
# File 'lib/guard/exec.rb', line 70

def run_on_additions(paths)
end

#run_on_modifications(paths) ⇒ Object

Called on file(s) modifications that the Guard plugin watches.

Parameters:

  • paths (Array<String>)

    the changes files or paths

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when run_on_modifications has failed



79
80
81
82
83
84
85
# File 'lib/guard/exec.rb', line 79

def run_on_modifications(paths)
  return if paths.empty?

  Compat::UI.info("Running: [#{paths.join(', ')}]", reset: true)

  runner.run(paths)
end

#run_on_removals(paths) ⇒ Object

Called on file(s) removals that the Guard plugin watches.

Parameters:

  • paths (Array<String>)

    the changes files or paths

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when run_on_removals has failed



93
94
# File 'lib/guard/exec.rb', line 93

def run_on_removals(paths)
end

#startObject

Called once when Guard starts. Please override initialize method to init stuff.

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when start has failed



32
33
# File 'lib/guard/exec.rb', line 32

def start
end

#stopObject

Called when ‘stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when stop has failed



40
41
# File 'lib/guard/exec.rb', line 40

def stop
end