Module: Guard::Commander

Included in:
Guard
Defined in:
lib/guard/commander.rb

Instance Method Summary collapse

Instance Method Details

#pauseObject

Pause Guard listening to file changes.



86
87
88
89
90
91
92
93
94
# File 'lib/guard/commander.rb', line 86

def pause
  if listener.paused?
    ::Guard::UI.info 'Un-paused files modification listening', reset: true
    listener.unpause
  else
    ::Guard::UI.info 'Paused files modification listening', reset: true
    listener.pause
  end
end

#reload(scopes = {}) ⇒ Object

Reload Guardfile and all Guard plugins currently enabled. If no scope is given, then the Guardfile will be re-evaluated, which results in a stop/start, which makes the reload obsolete.

Parameters:

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

    hash with a Guard plugin or a group scope



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/guard/commander.rb', line 55

def reload(scopes = {})
  setup unless running

  within_preserved_state do
    ::Guard::UI.clear(force: true)
    ::Guard::UI.action_with_scopes('Reload', scopes)

    if scopes.empty?
      evaluator.reevaluate_guardfile
    else
      runner.run(:reload, scopes)
    end
  end
end

#run_all(scopes = {}) ⇒ Object

Trigger `run_all` on all Guard plugins currently enabled.

Parameters:

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

    hash with a Guard plugin or a group scope



74
75
76
77
78
79
80
81
82
# File 'lib/guard/commander.rb', line 74

def run_all(scopes = {})
  setup unless running

  within_preserved_state do
    ::Guard::UI.clear(force: true)
    ::Guard::UI.action_with_scopes('Run', scopes)
    runner.run(:run_all, scopes)
  end
end

#start(options = {}) ⇒ Object

Start Guard by evaluating the `Guardfile`, initializing declared Guard plugins and starting the available file change listener. Main method for Guard that is called from the CLI when Guard starts.

  • Setup Guard internals

  • Evaluate the `Guardfile`

  • Configure Notifiers

  • Initialize the declared Guard plugins

  • Start the available file change listener

Parameters:

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

    a customizable set of options

Options Hash (options):

  • clear (Boolean)

    if auto clear the UI should be done

  • notify (Boolean)

    if system notifications should be shown

  • debug (Boolean)

    if debug output should be shown

  • group (Array<String>)

    the list of groups to start

  • watchdir (String)

    the director to watch

  • guardfile (String)

    the path to the Guardfile

See Also:



23
24
25
26
27
28
29
30
31
32
# File 'lib/guard/commander.rb', line 23

def start(options = {})
  setup(options) unless running

  within_preserved_state do
    ::Guard::UI.debug 'Guard starts all plugins'
    runner.run(:start)
    ::Guard::UI.info "Guard is now watching at '#{ @watchdirs.join "', '" }'"
    listener.start
  end
end

#stopObject

Stop Guard listening to file changes.



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/guard/commander.rb', line 36

def stop
  setup unless running

  within_preserved_state do
    ::Guard::UI.debug 'Guard stops all plugins'
    runner.run(:stop)
    ::Guard::Notifier.turn_off
    ::Guard::UI.info 'Bye bye...', reset: true
    listener.stop
    @running = false
  end
end

#within_preserved_state { ... } ⇒ Object

Runs a block where the interactor is blocked and execution is synchronized to avoid state inconsistency.

Parameters:

  • restart_interactor (Boolean)

    whether to restart the interactor or not

Yields:

  • the block to run



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/guard/commander.rb', line 104

def within_preserved_state
  lock.synchronize do
    begin
      interactor.stop if interactor
      @result = yield
    rescue Interrupt
      # Bring back Pry when the block is halted with Ctrl-C
    end

    interactor.start if interactor && running
  end

  @result
end