Class: Guard::Engine
- Inherits:
-
Object
- Object
- Guard::Engine
- Extended by:
- Forwardable
- Includes:
- Internals::Helpers
- Defined in:
- lib/guard/engine.rb
Overview
Engine is the main orchestrator class.
Instance Method Summary collapse
- #evaluator ⇒ Object
-
#initialize(options = {}) ⇒ Guard::Engine
constructor
Initialize a new Guard::Engine object.
-
#pause(expected = nil) ⇒ Object
Pause Guard listening to file changes.
-
#reload(*entries) ⇒ Object
Reload Guardfile and all Guard plugins currently enabled.
-
#run_all(*entries) ⇒ Object
Trigger
run_all
on all Guard plugins currently enabled. - #session ⇒ Object
-
#setup ⇒ Object
Evaluate the Guardfile and instantiate internals.
- #show ⇒ Object
-
#start ⇒ Object
Start Guard by evaluating the
Guardfile
, initializing declared Guard plugins and starting the available file change listener. - #stop ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(options = {}) ⇒ Guard::Engine
Initialize a new Guard::Engine object.
40 41 42 43 |
# File 'lib/guard/engine.rb', line 40 def initialize( = {}) @options = Thread.current[:engine] = self end |
Instance Method Details
#evaluator ⇒ Object
49 50 51 |
# File 'lib/guard/engine.rb', line 49 def evaluator @evaluator ||= Guardfile::Evaluator.new() end |
#pause(expected = nil) ⇒ Object
Pause Guard listening to file changes.
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/guard/engine.rb', line 164 def pause(expected = nil) states = { paused: true, unpaused: false, toggle: !paused? } key = expected || :toggle raise ArgumentError, "invalid mode: #{expected.inspect}" unless states.key?(key) pause = states[key] return if pause == paused? _listener.public_send(pause ? :pause : :start) UI.info "File event handling has been #{pause ? 'paused' : 'resumed'}" end |
#reload(*entries) ⇒ 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.
144 145 146 147 148 149 |
# File 'lib/guard/engine.rb', line 144 def reload(*entries) entries.flatten! UI.clear(force: true) UI.action_with_scopes("Reload", session.scope_titles(entries)) _runner.run(:reload, entries) end |
#run_all(*entries) ⇒ Object
Trigger run_all
on all Guard plugins currently enabled.
155 156 157 158 159 160 |
# File 'lib/guard/engine.rb', line 155 def run_all(*entries) entries.flatten! UI.clear(force: true) UI.action_with_scopes("Run", session.scope_titles(entries)) _runner.run(:run_all, entries) end |
#session ⇒ Object
45 46 47 |
# File 'lib/guard/engine.rb', line 45 def session @session ||= Guard::Internals::Session.new() end |
#setup ⇒ Object
Evaluate the Guardfile and instantiate internals.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/guard/engine.rb', line 63 def setup _instantiate UI.reset_and_clear if evaluator.inline? UI.info("Using inline Guardfile.") elsif evaluator.custom? UI.info("Using Guardfile at #{evaluator.guardfile_path}.") end self end |
#show ⇒ Object
177 178 179 |
# File 'lib/guard/engine.rb', line 177 def show DslDescriber.new(self).show end |
#start ⇒ 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
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/guard/engine.rb', line 95 def start setup _initialize_listener _initialize_signal_traps _initialize_notifier UI.debug "Guard starts all plugins" _runner.run(:start) UI.info "Guard is now watching at '#{session.watchdirs.join("', '")}'" _listener.start exitcode = 0 begin loop do break if _interactor.foreground == :exit loop do break unless _queue.pending? _queue.process end end rescue Interrupt rescue SystemExit => e exitcode = e.status end exitcode ensure stop end |
#stop ⇒ Object
129 130 131 132 133 134 135 136 |
# File 'lib/guard/engine.rb', line 129 def stop _listener.stop _interactor.background UI.debug "Guard stops all plugins" _runner.run(:stop) Notifier.disconnect UI.info "Bye bye...", reset: true end |
#to_s ⇒ Object Also known as: inspect
53 54 55 |
# File 'lib/guard/engine.rb', line 53 def to_s "#<#{self.class}:#{object_id} @options=#{}>" end |