Module: Guard::Setuper
- Included in:
- Guard
- Defined in:
- lib/guard/setuper.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ clear: false, notify: true, debug: false, group: [], plugin: [], watchdir: nil, guardfile: nil, no_interactions: false, no_bundler_warning: false, show_deprecations: false, latency: nil, force_polling: false, wait_for_delay: nil, listen_on: nil }
- DEFAULT_GROUPS =
[:default]
Instance Method Summary collapse
-
#clear_options ⇒ Object
Clear Guard's options hash.
-
#evaluate_guardfile ⇒ Object
Evaluates the Guardfile content.
-
#evaluator ⇒ Object
Lazy initializer for Guardfile evaluator.
-
#interactor ⇒ Object
Lazy initializer the interactor unless the user has specified not to.
-
#options ⇒ Object
Lazy initializer for Guard's options hash.
-
#reset_groups ⇒ Object
Initializes the groups array with the default group(s).
-
#reset_plugins ⇒ Object
Initializes the plugins array to an empty array.
-
#reset_scope ⇒ Object
Initializes the scope hash to `{ groups: [], plugins: [] }`.
-
#setup(opts = {}) ⇒ Guard
Initializes the Guard singleton:.
-
#setup_scope(new_scope) ⇒ Object
Stores the scopes defined by the user via the `–group` / `-g` option (to run only a specific group) or the `–plugin` / `-P` option (to run only a specific plugin).
Instance Method Details
#clear_options ⇒ Object
Clear Guard's options hash
95 96 97 |
# File 'lib/guard/setuper.rb', line 95 def @options = nil end |
#evaluate_guardfile ⇒ Object
Evaluates the Guardfile content. It displays an error message if no Guard plugins are instantiated after the Guardfile evaluation.
145 146 147 148 |
# File 'lib/guard/setuper.rb', line 145 def evaluate_guardfile evaluator.evaluate_guardfile ::Guard::UI.error 'No plugins found in Guardfile, please add at least one.' if plugins.empty? end |
#evaluator ⇒ Object
Lazy initializer for Guardfile evaluator
81 82 83 |
# File 'lib/guard/setuper.rb', line 81 def evaluator @evaluator ||= ::Guard::Guardfile::Evaluator.new(@opts || {}) end |
#interactor ⇒ Object
Lazy initializer the interactor unless the user has specified not to.
87 88 89 90 91 |
# File 'lib/guard/setuper.rb', line 87 def interactor return if [:no_interactions] || !::Guard::Interactor.enabled @interactor ||= ::Guard::Interactor.new end |
#options ⇒ Object
Lazy initializer for Guard's options hash
75 76 77 |
# File 'lib/guard/setuper.rb', line 75 def @options ||= ::Guard::Options.new(@opts, DEFAULT_OPTIONS) end |
#reset_groups ⇒ Object
Initializes the groups array with the default group(s).
103 104 105 |
# File 'lib/guard/setuper.rb', line 103 def reset_groups @groups = DEFAULT_GROUPS.map { |name| Group.new(name) } end |
#reset_plugins ⇒ Object
Initializes the plugins array to an empty array.
111 112 113 |
# File 'lib/guard/setuper.rb', line 111 def reset_plugins @plugins = [] end |
#reset_scope ⇒ Object
Initializes the scope hash to `{ groups: [], plugins: [] }`.
119 120 121 |
# File 'lib/guard/setuper.rb', line 119 def reset_scope @scope = { groups: [], plugins: [] } end |
#setup(opts = {}) ⇒ Guard
Initializes the Guard singleton:
-
Initialize the internal Guard state;
-
Create the interactor when necessary for user interaction;
-
Select and initialize the file change listener.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/guard/setuper.rb', line 42 def setup(opts = {}) _reset_lazy_accessors @running = true @lock = Mutex.new @opts = opts @watchdirs = [Dir.pwd] @runner = ::Guard::Runner.new if [:watchdir] # Ensure we have an array @watchdirs = Array([:watchdir]).map { |dir| File. dir } end ::Guard::UI.clear(force: true) _setup_debug if [:debug] _setup_listener _setup_signal_traps reset_groups reset_plugins reset_scope evaluate_guardfile setup_scope(groups: [:group], plugins: [:plugin]) _setup_notifier self end |
#setup_scope(new_scope) ⇒ Object
Stores the scopes defined by the user via the `–group` / `-g` option (to run only a specific group) or the `–plugin` / `-P` option (to run only a specific plugin).
130 131 132 133 134 135 136 137 138 |
# File 'lib/guard/setuper.rb', line 130 def setup_scope(new_scope) if new_scope[:groups] && new_scope[:groups].any? scope[:groups] = new_scope[:groups].map { |group| ::Guard.add_group(group) } end if new_scope[:plugins] && new_scope[:plugins].any? scope[:plugins] = new_scope[:plugins].map { |plugin| ::Guard.plugin(plugin) } end end |