guard 2.7.2 → 2.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,103 @@
1
+ module Guard
2
+ # Commands supported by guard
3
+ module Commander
4
+ # Start Guard by evaluating the `Guardfile`, initializing declared Guard
5
+ # plugins and starting the available file change listener.
6
+ # Main method for Guard that is called from the CLI when Guard starts.
7
+ #
8
+ # - Setup Guard internals
9
+ # - Evaluate the `Guardfile`
10
+ # - Configure Notifiers
11
+ # - Initialize the declared Guard plugins
12
+ # - Start the available file change listener
13
+ #
14
+ # @option options [Boolean] clear if auto clear the UI should be done
15
+ # @option options [Boolean] notify if system notifications should be shown
16
+ # @option options [Boolean] debug if debug output should be shown
17
+ # @option options [Array<String>] group the list of groups to start
18
+ # @option options [String] watchdir the director to watch
19
+ # @option options [String] guardfile the path to the Guardfile
20
+ # @see CLI#start
21
+ #
22
+ def start(options = {})
23
+ setup(options)
24
+ ::Guard::UI.debug "Guard starts all plugins"
25
+ runner.run(:start)
26
+ listener.start
27
+ <<<<<<< HEAD
28
+
29
+ watched = ::Guard.watchdirs.join("', '")
30
+ ::Guard::UI.info "Guard is now watching at '#{ watched }'"
31
+ =======
32
+ ::Guard::UI.info "Guard is now watching at '#{ ::Guard.watchdirs.join "', '" }'"
33
+ >>>>>>> origin/api_safe_refactoring
34
+
35
+ _interactor_loop
36
+ end
37
+
38
+ # TODO: refactor (left to avoid breaking too many specs)
39
+ def stop
40
+ listener.stop
41
+ interactor.background
42
+ ::Guard::UI.debug "Guard stops all plugins"
43
+ runner.run(:stop)
44
+ ::Guard::Notifier.turn_off
45
+ ::Guard::UI.info "Bye bye...", reset: true
46
+ end
47
+
48
+ # Reload Guardfile and all Guard plugins currently enabled.
49
+ # If no scope is given, then the Guardfile will be re-evaluated,
50
+ # which results in a stop/start, which makes the reload obsolete.
51
+ #
52
+ # @param [Hash] scopes hash with a Guard plugin or a group scope
53
+ #
54
+ def reload(scopes = {})
55
+ ::Guard::UI.clear(force: true)
56
+ ::Guard::UI.action_with_scopes("Reload", scopes)
57
+
58
+ if scopes.empty?
59
+ evaluator.reevaluate_guardfile
60
+ else
61
+ runner.run(:reload, scopes)
62
+ end
63
+ end
64
+
65
+ # Trigger `run_all` on all Guard plugins currently enabled.
66
+ #
67
+ # @param [Hash] scopes hash with a Guard plugin or a group scope
68
+ #
69
+ def run_all(scopes = {})
70
+ ::Guard::UI.clear(force: true)
71
+ ::Guard::UI.action_with_scopes("Run", scopes)
72
+ runner.run(:run_all, scopes)
73
+ end
74
+
75
+ # Pause Guard listening to file changes.
76
+ #
77
+ def pause(expected = nil)
78
+ paused = listener.paused?
79
+ states = { paused: true, unpaused: false, toggle: !paused }
80
+ pause = states[expected || :toggle]
81
+ fail ArgumentError, "invalid mode: #{expected.inspect}" if pause.nil?
82
+ return if pause == paused
83
+
84
+ listener.send(pause ? :pause : :unpause)
85
+ UI.info "File modification listening is now #{pause.to_s.upcase}"
86
+ end
87
+
88
+ def show
89
+ ::Guard::DslDescriber.new(::Guard.options).show
90
+ end
91
+
92
+ private
93
+
94
+ # TODO: remove (left to avoid breaking too many specs)
95
+ def _interactor_loop
96
+ while interactor.foreground != :exit
97
+ _process_queue while pending_changes?
98
+ end
99
+ rescue Interrupt
100
+ stop
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,36 @@
1
+ # required for async_queue_add
2
+ require "pry"
3
+ require "guard"
4
+
5
+ module Guard
6
+ module Commands
7
+ class All
8
+ def self.import
9
+ Pry::Commands.create_command "all" do
10
+ group "Guard"
11
+ description "Run all plugins."
12
+
13
+ banner <<-BANNER
14
+ Usage: all <scope>
15
+
16
+ Run the Guard plugin `run_all` action.
17
+
18
+ You may want to specify an optional scope to the action,
19
+ either the name of a Guard plugin or a plugin group.
20
+ BANNER
21
+
22
+ def process(*entries)
23
+ scopes, unknown = ::Guard::Interactor.convert_scope(entries)
24
+
25
+ unless unknown.empty?
26
+ output.puts "Unknown scopes: #{ unknown.join(", ") }"
27
+ return
28
+ end
29
+
30
+ ::Guard.async_queue_add([:guard_run_all, scopes])
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,34 @@
1
+ require "pry"
2
+
3
+ module Guard
4
+ module Commands
5
+ class Reload
6
+ def self.import
7
+ Pry::Commands.create_command "reload" do
8
+ group "Guard"
9
+ description "Reload all plugins."
10
+
11
+ banner <<-BANNER
12
+ Usage: reload <scope>
13
+
14
+ Run the Guard plugin `reload` action.
15
+
16
+ You may want to specify an optional scope to the action,
17
+ either the name of a Guard plugin or a plugin group.
18
+ BANNER
19
+
20
+ def process(*entries)
21
+ scopes, unknown = ::Guard::Interactor.convert_scope(entries)
22
+
23
+ unless unknown.empty?
24
+ output.puts "Unknown scopes: #{ unknown.join(", ") }"
25
+ return
26
+ end
27
+
28
+ ::Guard.async_queue_add([:guard_reload, scopes])
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ require "pry"
2
+
3
+ module Guard
4
+ module Commands
5
+ class Scope
6
+ def self.import
7
+ Pry::Commands.create_command "scope" do
8
+ group "Guard"
9
+ description "Scope Guard actions to groups and plugins."
10
+
11
+ banner <<-BANNER
12
+ Usage: scope <scope>
13
+
14
+ Set the global Guard scope.
15
+ BANNER
16
+
17
+ def process(*entries)
18
+ scope, unknown = ::Guard::Interactor.convert_scope(entries)
19
+
20
+ unless unknown.empty?
21
+ output.puts "Unknown scopes: #{unknown.join(",") }"
22
+ return
23
+ end
24
+
25
+ if scope[:plugins].empty? && scope[:groups].empty?
26
+ output.puts "Usage: scope <scope>"
27
+ return
28
+ end
29
+
30
+ ::Guard.setup_scope(scope)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,71 @@
1
+ module Guard
2
+ module DeprecatedMethods
3
+ # @deprecated Use `Guard.plugins(filter)` instead.
4
+ #
5
+ # @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
6
+ # upgrade for Guard 2.0
7
+ #
8
+ def guards(filter = nil)
9
+ ::Guard::UI.deprecation(::Guard::Deprecator::GUARDS_DEPRECATION)
10
+ plugins(filter)
11
+ end
12
+
13
+ # @deprecated Use `Guard.add_plugin(name, options = {})` instead.
14
+ #
15
+ # @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
16
+ # upgrade for Guard 2.0
17
+ #
18
+ def add_guard(*args)
19
+ ::Guard::UI.deprecation(::Guard::Deprecator::ADD_GUARD_DEPRECATION)
20
+ add_plugin(*args)
21
+ end
22
+
23
+ # @deprecated Use
24
+ # `Guard::PluginUtil.new(name).plugin_class(fail_gracefully:
25
+ # fail_gracefully)` instead.
26
+ #
27
+ # @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
28
+ # upgrade for Guard 2.0
29
+ #
30
+ def get_guard_class(name, fail_gracefully = false)
31
+ UI.deprecation(Deprecator::GET_GUARD_CLASS_DEPRECATION)
32
+ PluginUtil.new(name).plugin_class(fail_gracefully: fail_gracefully)
33
+ end
34
+
35
+ # @deprecated Use `Guard::PluginUtil.new(name).plugin_location` instead.
36
+ #
37
+ # @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
38
+ # upgrade for Guard 2.0
39
+ #
40
+ def locate_guard(name)
41
+ UI.deprecation(Deprecator::LOCATE_GUARD_DEPRECATION)
42
+ PluginUtil.new(name).plugin_location
43
+ end
44
+
45
+ # @deprecated Use `Guard::PluginUtil.plugin_names` instead.
46
+ #
47
+ # @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
48
+ # upgrade for Guard 2.0
49
+ #
50
+ def guard_gem_names
51
+ UI.deprecation(Deprecator::GUARD_GEM_NAMES_DEPRECATION)
52
+ PluginUtil.plugin_names
53
+ end
54
+
55
+ def running
56
+ UI.deprecation(Deprecator::GUARD_RUNNING_DEPRECATION)
57
+ nil
58
+ end
59
+
60
+ def lock
61
+ UI.deprecation(Deprecator::GUARD_LOCK_DEPRECATION)
62
+ end
63
+
64
+ def evaluator
65
+ UI.deprecation(Deprecator::GUARD_EVALUATOR_DEPRECATION)
66
+ # TODO: this will be changed to the following when scope is reworked
67
+ # ::Guard.session.evaluator
68
+ ::Guard.instance_variable_get(:@evaluator)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,206 @@
1
+ require "guard/ui"
2
+
3
+ module Guard
4
+ class Deprecator
5
+ UPGRADE_WIKI = "https://github.com/guard/guard/wiki"\
6
+ "/Upgrade-guide-for-existing-guards-to-Guard-v1.1"
7
+
8
+ MORE_INFO_ON_UPGRADING_TO_GUARD_1_1 = <<-EOS.gsub(/^\s*/, "")
9
+ For more information on how to update existing Guard plugins, please head
10
+ over to:
11
+ #{UPGRADE_WIKI}
12
+ EOS
13
+
14
+ MORE_INFO_ON_UPGRADING_TO_GUARD_2 = <<-EOS.gsub(/^\s*/, "")
15
+ For more information on how to upgrade for Guard 2.0, please head over
16
+ to: https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0%s
17
+ EOS
18
+
19
+ ADD_GUARD_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
20
+ Starting with Guard 2.0 'Guard.add_guard(name, options = {})' is
21
+ deprecated.
22
+
23
+ Please use 'Guard.add_plugin(name, options = {})' instead.
24
+
25
+ #{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#deprecated-methods"}
26
+ EOS
27
+
28
+ GUARDS_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
29
+ Starting with Guard 2.0 'Guard.guards(filter)' is deprecated.
30
+
31
+ Please use 'Guard.plugins(filter)' instead.
32
+
33
+ #{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#deprecated-methods"}
34
+ EOS
35
+
36
+ # Deprecator message for the `Guard.get_guard_class` method
37
+ GET_GUARD_CLASS_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
38
+ Starting with Guard 2.0 'Guard.get_guard_class(name, fail_gracefully =
39
+ false)' is deprecated and is now always on.
40
+
41
+ Please use 'Guard::PluginUtil.new(name).plugin_class(fail_gracefully:
42
+ fail_gracefully)' instead.
43
+
44
+ #{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#deprecated-methods"}
45
+ EOS
46
+
47
+ # Deprecator message for the `Guard.locate_guard` method
48
+ LOCATE_GUARD_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
49
+ Starting with Guard 2.0 'Guard.locate_guard(name)' is deprecated.
50
+
51
+ Please use 'Guard::PluginUtil.new(name).plugin_location' instead.
52
+
53
+ #{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#deprecated-methods"}
54
+ EOS
55
+
56
+ # Deprecator message for the `Guard.guard_gem_names` method
57
+ GUARD_GEM_NAMES_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
58
+ Starting with Guard 2.0 'Guard.guard_gem_names' is deprecated.
59
+
60
+ Please use 'Guard::PluginUtil.plugin_names' instead.
61
+
62
+ #{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#deprecated-methods"}
63
+ EOS
64
+
65
+ # Deprecator message for the `Guard::Dsl.evaluate_guardfile` method
66
+ EVALUATE_GUARDFILE_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
67
+ Starting with Guard 2.0 'Guard::Dsl.evaluate_guardfile(options)' is
68
+ deprecated.
69
+
70
+ Please use 'Guard::Guardfile::Evaluator.new(options).evaluate_guardfile'
71
+ instead.
72
+
73
+ #{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#deprecated-methods-1"}
74
+ EOS
75
+
76
+ # Deprecator message for the `Guardfile.create_guardfile` method
77
+ CREATE_GUARDFILE_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
78
+ Starting with Guard 2.0 'Guard::Guardfile.create_guardfile(options)' is
79
+ deprecated.
80
+
81
+ Please use 'Guard::Guardfile::Generator.new(options).create_guardfile'
82
+ instead.
83
+
84
+ #{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#deprecated-methods-2"}
85
+ EOS
86
+
87
+ # Deprecator message for the `Guardfile.initialize_template` method
88
+ INITIALIZE_TEMPLATE_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
89
+ Starting with Guard 2.0
90
+ 'Guard::Guardfile.initialize_template(plugin_name)' is deprecated.
91
+
92
+ Please use
93
+ 'Guard::Guardfile::Generator.new.initialize_template(plugin_name)'
94
+ instead.
95
+
96
+ #{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#deprecated-methods-2"}
97
+ EOS
98
+
99
+ # Deprecator message for the `Guardfile.initialize_all_templates` method
100
+ INITIALIZE_ALL_TEMPLATES_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
101
+ Starting with Guard 2.0 'Guard::Guardfile.initialize_all_templates' is
102
+ deprecated.
103
+
104
+ Please use 'Guard::Guardfile::Generator.new.initialize_all_templates'
105
+ instead.
106
+
107
+ #{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#deprecated-methods-2"}
108
+ EOS
109
+
110
+ # Deprecator message for when a Guard plugin inherits from Guard::Guard
111
+ GUARD_GUARD_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
112
+ Starting with Guard 2.0, Guard::%s should inherit from Guard::Plugin
113
+ instead of Guard::Guard.
114
+
115
+ Please note that the constructor signature has changed from
116
+ Guard::Guard#initialize(watchers = [], options = {}) to
117
+ Guard::Plugin#initialize(options = {}).
118
+
119
+ #{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#changes-in-guardguard"}
120
+ EOS
121
+
122
+ <<<<<<< HEAD
123
+ GUARD_RUNNING_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
124
+ Starting with Guard 2.7.1 it was discovered that Guard.running was never
125
+ initialized or used internally.
126
+ EOS
127
+
128
+ GUARD_LOCK_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
129
+ Starting with Guard 2.7.1 it was discovered that this accessor was never
130
+ initialized or used internally.
131
+ EOS
132
+
133
+ GUARD_EVALUATOR_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
134
+ Starting with Guard 2.7.1 ::Guard.session.evaluator should be used
135
+ instead.
136
+ EOS
137
+ =======
138
+ # Deprecator message for the `watch_all_modifications` start option
139
+ WATCH_ALL_MODIFICATIONS_DEPRECATION = <<-EOS.gsub(/^\s*/, '')
140
+ Starting with Guard 1.1 the 'watch_all_modifications' option is removed
141
+ and is now always on.
142
+ EOS
143
+
144
+ # Deprecator message for the `no_vendor` start option
145
+ NO_VENDOR_DEPRECATION = <<-EOS.gsub(/^\s*/, '')
146
+ Starting with Guard 1.1 the 'no_vendor' option is removed because the
147
+ monitoring gems are now part of a new gem called Listen.
148
+ (https://github.com/guard/listen)
149
+
150
+ You can specify a custom version of any monitoring gem directly in your
151
+ Gemfile if you want to overwrite Listen's default monitoring gems.
152
+ EOS
153
+
154
+ # Deprecator message for the `run_on_change` method
155
+ RUN_ON_CHANGE_DEPRECATION = <<-EOS.gsub(/^\s*/, '')
156
+ Starting with Guard 1.1 the use of the 'run_on_change' method in the '%s' guard is deprecated.
157
+
158
+ Please consider replacing that method-call with 'run_on_changes' if the type of change
159
+ is not important for your usecase or using either 'run_on_modifications' or 'run_on_additions'
160
+ based on the type of the changes you want to handle.
161
+
162
+ #{MORE_INFO_ON_UPGRADING_TO_GUARD_1_1}
163
+ EOS
164
+
165
+ # Deprecator message for the `run_on_deletion` method
166
+ RUN_ON_DELETION_DEPRECATION = <<-EOS.gsub(/^\s*/, '')
167
+ Starting with Guard 1.1 the use of the 'run_on_deletion' method in the '%s' guard is deprecated.
168
+
169
+ Please consider replacing that method-call with 'run_on_removals' for future proofing your code.
170
+
171
+ #{MORE_INFO_ON_UPGRADING_TO_GUARD_1_1}
172
+ EOS
173
+
174
+ # Deprecator message for the `interactor` method
175
+ DSL_METHOD_INTERACTOR_DEPRECATION = <<-EOS.gsub(/^\s*/, '')
176
+ Starting with Guard 1.4 the use of the 'interactor' Guardfile DSL method is only used to
177
+ disable or pass options to the Pry interactor. All other usages are deprecated.
178
+ EOS
179
+
180
+ # Deprecator message for the `ignore_paths` method
181
+ DSL_METHOD_IGNORE_PATHS_DEPRECATION = <<-EOS.gsub(/^\s*/, '')
182
+ Starting with Guard 1.1 the use of the 'ignore_paths' Guardfile DSL method is deprecated.
183
+
184
+ Please replace that method with the better 'ignore' or/and 'filter' methods.
185
+ Documentation on the README: https://github.com/guard/guard#ignore
186
+ EOS
187
+
188
+ # Displays a warning for each deprecated options used when starting Guard.
189
+ #
190
+ def self.deprecated_options_warning(options)
191
+ ::Guard::UI.deprecation(WATCH_ALL_MODIFICATIONS_DEPRECATION) if options.watch_all_modifications
192
+ ::Guard::UI.deprecation(NO_VENDOR_DEPRECATION) if options.no_vendor
193
+ end
194
+
195
+ # Displays a warning for each deprecated method used is any registered Guard plugin.
196
+ #
197
+ def self.deprecated_plugin_methods_warning
198
+ ::Guard.plugins.each do |plugin|
199
+ ::Guard::UI.deprecation(RUN_ON_CHANGE_DEPRECATION % plugin.class.name) if plugin.respond_to?(:run_on_change)
200
+ ::Guard::UI.deprecation(RUN_ON_DELETION_DEPRECATION % plugin.class.name) if plugin.respond_to?(:run_on_deletion)
201
+ end
202
+ end
203
+
204
+ >>>>>>> parent of a5162d2... Remove deprecated methods and options. Fixes #425.
205
+ end
206
+ end