guard 2.8.2 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -7
  3. data/lib/guard.rb +220 -152
  4. data/lib/guard.rb.orig +213 -155
  5. data/lib/guard/aruba_adapter.rb +2 -2
  6. data/lib/guard/cli.rb +8 -13
  7. data/lib/guard/cli.rb.orig +12 -10
  8. data/lib/guard/commander.rb +15 -7
  9. data/lib/guard/commands/all.rb +3 -0
  10. data/lib/guard/commands/change.rb +3 -0
  11. data/lib/guard/commands/pause.rb +2 -0
  12. data/lib/guard/commands/reload.rb +4 -0
  13. data/lib/guard/commands/scope.rb +3 -0
  14. data/lib/guard/config.rb +24 -0
  15. data/lib/guard/deprecated/dsl.rb +45 -0
  16. data/lib/guard/deprecated/guard.rb +166 -0
  17. data/lib/guard/deprecated/guardfile.rb +84 -0
  18. data/lib/guard/dsl.rb +24 -13
  19. data/lib/guard/dsl.rb.orig +378 -0
  20. data/lib/guard/dsl_describer.rb +8 -2
  21. data/lib/guard/dsl_describer.rb.orig +11 -3
  22. data/lib/guard/guardfile.rb +32 -44
  23. data/lib/guard/guardfile/evaluator.rb +13 -6
  24. data/lib/guard/guardfile/generator.rb +4 -3
  25. data/lib/guard/interactor.rb +7 -3
  26. data/lib/guard/internals/debugging.rb +1 -0
  27. data/lib/guard/internals/environment.rb +93 -0
  28. data/lib/guard/internals/helpers.rb +13 -0
  29. data/lib/guard/internals/traps.rb +10 -0
  30. data/lib/guard/jobs/pry_wrapper.rb +4 -3
  31. data/lib/guard/jobs/sleep.rb +2 -0
  32. data/lib/guard/metadata.rb +190 -0
  33. data/lib/guard/notifier.rb +124 -99
  34. data/lib/guard/notifier.rb.orig +124 -99
  35. data/lib/guard/notifier/detected.rb +83 -0
  36. data/lib/guard/notifiers/emacs.rb +2 -1
  37. data/lib/guard/notifiers/tmux.rb +173 -177
  38. data/lib/guard/plugin/base.rb +2 -0
  39. data/lib/guard/plugin_util.rb +26 -32
  40. data/lib/guard/reevaluator.rb +3 -3
  41. data/lib/guard/reevaluator.rb.orig +22 -0
  42. data/lib/guard/runner.rb +1 -0
  43. data/lib/guard/session.rb +5 -0
  44. data/lib/guard/sheller.rb +2 -2
  45. data/lib/guard/templates/Guardfile +4 -0
  46. data/lib/guard/templates/Guardfile.orig +2 -0
  47. data/lib/guard/terminal.rb +1 -0
  48. data/lib/guard/ui.rb +4 -1
  49. data/lib/guard/version.rb +1 -1
  50. data/lib/guard/version.rb.orig +1 -1
  51. data/lib/guard/watcher.rb +3 -1
  52. data/lib/guard/watcher.rb.orig +122 -0
  53. data/man/guard.1 +1 -4
  54. data/man/guard.1.html +1 -4
  55. metadata +17 -25
  56. data/lib/guard/commander.rb.orig +0 -103
  57. data/lib/guard/commands/all.rb.orig +0 -36
  58. data/lib/guard/commands/reload.rb.orig +0 -34
  59. data/lib/guard/commands/scope.rb.orig +0 -36
  60. data/lib/guard/deprecated_methods.rb +0 -72
  61. data/lib/guard/deprecated_methods.rb.orig +0 -71
  62. data/lib/guard/deprecator.rb +0 -133
  63. data/lib/guard/deprecator.rb.orig +0 -206
  64. data/lib/guard/guard.rb +0 -100
  65. data/lib/guard/guard.rb.orig +0 -42
  66. data/lib/guard/guardfile.rb.orig +0 -43
  67. data/lib/guard/guardfile/evaluator.rb.orig +0 -275
  68. data/lib/guard/internals/debugging.rb.orig +0 -0
  69. data/lib/guard/internals/environment.rb.orig +0 -0
  70. data/lib/guard/internals/tracing.rb.orig +0 -0
  71. data/lib/guard/notifiers/base.rb.orig +0 -221
  72. data/lib/guard/notifiers/tmux.rb.orig +0 -339
  73. data/lib/guard/plugin_util.rb.orig +0 -186
  74. data/lib/guard/runner.rb.orig +0 -210
  75. data/lib/guard/setuper.rb +0 -359
  76. data/lib/guard/setuper.rb.orig +0 -395
  77. data/lib/guard/ui.rb.orig +0 -278
@@ -1,206 +0,0 @@
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
data/lib/guard/guard.rb DELETED
@@ -1,100 +0,0 @@
1
- require "guard/plugin/base"
2
-
3
- module Guard
4
- unless ENV["GUARD_GEM_SILENCE_DEPRECATIONS"] == "1"
5
-
6
- UPGRADE_WIKI_URL =
7
- "https://github.com/guard/guard/" +
8
- "wiki/Upgrading-to-Guard-2.0#changes-in-guardguard"
9
-
10
- STDERR.puts <<-EOS
11
-
12
- ******** BIG DEPRECATION WARNING !! ********
13
-
14
- Hi, Guard here.
15
-
16
- You're including lib/guard/guard.rb ...
17
-
18
- ... which contains code deprecated over a year ago!
19
-
20
-
21
- This file will likely be removed in the next version, so make sure you're
22
- not requiring it anywhere to ensure safe gem upgrades.
23
-
24
- If this message is annoying and you can't quickly fix the issue (see below),
25
- you have 2 options:
26
-
27
- 1) Simply set the env variable "GUARD_GEM_SILENCE_DEPRECATIONS" to "1" to
28
- skip this message
29
-
30
- 2) Freeze the gem to a previous version (not recommended because upgrades
31
- are cool and you might forget to unfreeze later!).
32
-
33
- E.g. in your Gemfile:
34
-
35
- if Time.now > Time.new(2014,11,10)
36
- gem 'guard', '~> 2.8'
37
- else
38
- # Freeze until 2014-11-10 - in case we forget to change back ;)
39
- gem 'guard', '= 2.7.3'
40
- end
41
-
42
- If you don't know which gem or plugin is requiring this file, here's a
43
- backtrace:
44
-
45
- #{Thread.current.backtrace[1..5].join("\n\t >> ")}"
46
-
47
- Here's how to quickly upgrade/fix this (given you are a maintainer of the
48
- offending plugin or you want to prepare a pull request yourself):
49
-
50
- #{UPGRADE_WIKI_URL}
51
-
52
- Have fun!
53
-
54
- ******** END OF DEPRECATION MESSAGE ********
55
-
56
- EOS
57
-
58
- end
59
- end
60
-
61
- module Guard
62
- # @deprecated Inheriting from `Guard::Guard` is deprecated, please inherit
63
- # from {Plugin} instead. Please note that the constructor signature has
64
- # changed from `Guard::Guard#initialize(watchers = [], options = {})` to
65
- # `Guard::Plugin#initialize(options = {})`.
66
- #
67
- # @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
68
- # upgrade for Guard 2.0
69
- #
70
- class Guard
71
- include ::Guard::Plugin::Base
72
-
73
- # @deprecated Inheriting from `Guard::Guard` is deprecated, please inherit
74
- # from {Plugin} instead. Please note that the constructor signature
75
- # has changed from `Guard::Guard#initialize(watchers = [], options = {})`
76
- # to `Guard::Plugin#initialize(options = {})`.
77
- #
78
- # Initializes a Guard plugin. Don't do any work here,
79
- # especially as Guard plugins get initialized even if they are not in an
80
- # active group!
81
- #
82
- # @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
83
- # upgrade for Guard 2.0
84
- #
85
- # @param [Array<Guard::Watcher>] watchers the Guard plugin file watchers
86
- # @param [Hash] options the custom Guard plugin options
87
- # @option options [Symbol] group the group this Guard plugin belongs to
88
- # @option options [Boolean] any_return allow any object to be returned from
89
- # a watcher
90
- # @option options [Boolean] first_match stop after the first watcher that
91
- # returns a valid result
92
- #
93
- def initialize(watchers = [], options = {})
94
- UI.deprecation(Deprecator::GUARD_GUARD_DEPRECATION % title)
95
-
96
- _set_instance_variables_from_options(options.merge(watchers: watchers))
97
- _register_callbacks
98
- end
99
- end
100
- end
@@ -1,42 +0,0 @@
1
- require "guard/plugin/base"
2
-
3
- module Guard
4
- # @deprecated Inheriting from `Guard::Guard` is deprecated, please inherit
5
- # from {Plugin} instead. Please note that the constructor signature has
6
- # changed from `Guard::Guard#initialize(watchers = [], options = {})` to
7
- # `Guard::Plugin#initialize(options = {})`.
8
- #
9
- # @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
10
- # upgrade for Guard 2.0
11
- #
12
- class Guard
13
- include ::Guard::Plugin::Base
14
-
15
- # @deprecated Inheriting from `Guard::Guard` is deprecated, please inherit
16
- # from {Plugin} instead. Please note that the constructor signature
17
- # has changed from `Guard::Guard#initialize(watchers = [], options = {})`
18
- # to `Guard::Plugin#initialize(options = {})`.
19
- #
20
- # Initializes a Guard plugin. Don't do any work here,
21
- # especially as Guard plugins get initialized even if they are not in an
22
- # active group!
23
- #
24
- # @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
25
- # upgrade for Guard 2.0
26
- #
27
- # @param [Array<Guard::Watcher>] watchers the Guard plugin file watchers
28
- # @param [Hash] options the custom Guard plugin options
29
- # @option options [Symbol] group the group this Guard plugin belongs to
30
- # @option options [Boolean] any_return allow any object to be returned from
31
- # a watcher
32
- # @option options [Boolean] first_match stop after the first watcher that
33
- # returns a valid result
34
- #
35
- def initialize(watchers = [], options = {})
36
- UI.deprecation(Deprecator::GUARD_GUARD_DEPRECATION % title)
37
-
38
- _set_instance_variables_from_options(options.merge(watchers: watchers))
39
- _register_callbacks
40
- end
41
- end
42
- end
@@ -1,43 +0,0 @@
1
- require "guard/guardfile/evaluator"
2
- require "guard/guardfile/generator"
3
- require "guard/ui"
4
-
5
- module Guard
6
- # @deprecated Use instance methods of {Guardfile::Evaluator} and
7
- # {Guardfile::Generator} instead.
8
- #
9
- # @see Guardfile::Evaluator
10
- # @see Guardfile::Generator
11
- #
12
- module Guardfile
13
- # @deprecated Use {Guardfile::Generator#create_guardfile} 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 self.create_guardfile(options = {})
19
- UI.deprecation(Deprecator::CREATE_GUARDFILE_DEPRECATION)
20
- Generator.new(options).create_guardfile
21
- end
22
-
23
- # @deprecated Use {Guardfile::Generator#initialize_template} instead.
24
- #
25
- # @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
26
- # upgrade for Guard 2.0
27
- #
28
- def self.initialize_template(plugin_name)
29
- UI.deprecation(Deprecator::INITIALIZE_TEMPLATE_DEPRECATION)
30
- Generator.new.initialize_template(plugin_name)
31
- end
32
-
33
- # @deprecated Use {Guardfile::Generator#initialize_all_templates} instead.
34
- #
35
- # @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
36
- # upgrade for Guard 2.0
37
- #
38
- def self.initialize_all_templates
39
- UI.deprecation(Deprecator::INITIALIZE_ALL_TEMPLATES_DEPRECATION)
40
- Generator.new.initialize_all_templates
41
- end
42
- end
43
- end
@@ -1,275 +0,0 @@
1
- require "guard/options"
2
- require "guard/plugin"
3
-
4
- module Guard
5
- module Guardfile
6
- # This class is responsible for evaluating the Guardfile. It delegates to
7
- # Guard::Dsl for the actual objects generation from the Guardfile content.
8
- #
9
- # @see Guard::Dsl
10
- #
11
- class Evaluator
12
- attr_reader :options, :guardfile_path
13
-
14
- def guardfile_source
15
- @source
16
- end
17
-
18
- # Initializes a new Guard::Guardfile::Evaluator object.
19
- #
20
- # @option opts [String] guardfile the path to a valid Guardfile
21
- # @option opts [String] guardfile_contents a string representing the
22
- # content of a valid Guardfile
23
- #
24
- def initialize(opts = {})
25
- @source = nil
26
- @guardfile_path = nil
27
-
28
- valid_options = opts.select do |k, _|
29
- [:guardfile, :guardfile_contents].include?(k.to_sym)
30
- end
31
-
32
- @options = ::Guard::Options.new(valid_options)
33
- end
34
-
35
- # Evaluates the DSL methods in the `Guardfile`.
36
- #
37
- # @example Programmatically evaluate a Guardfile
38
- # Guard::Guardfile::Evaluator.new.evaluate_guardfile
39
- #
40
- # @example Programmatically evaluate a Guardfile with a custom Guardfile
41
- # path
42
- #
43
- # options = { guardfile: '/Users/guardfile/MyAwesomeGuardfile' }
44
- # Guard::Guardfile::Evaluator.new(options).evaluate_guardfile
45
- #
46
- # @example Programmatically evaluate a Guardfile with an inline Guardfile
47
- #
48
- # options = { guardfile_contents: 'guard :rspec' }
49
- # Guard::Guardfile::Evaluator.new(options).evaluate_guardfile
50
- #
51
- def evaluate_guardfile
52
- _fetch_guardfile_contents
53
- _instance_eval_guardfile(guardfile_contents)
54
- ::Guard.add_builtin_plugins(guardfile_path)
55
- end
56
-
57
- # Re-evaluates the `Guardfile` to update
58
- # the current Guard configuration.
59
- #
60
- def reevaluate_guardfile
61
- # Don't re-evaluate inline Guardfile
62
- return if @source == :inline
63
-
64
- _before_reevaluate_guardfile
65
- evaluate_guardfile
66
- _after_reevaluate_guardfile
67
- end
68
-
69
- # Tests if the current `Guardfile` contains a specific Guard plugin.
70
- #
71
- # @example Programmatically test if a Guardfile contains a specific Guard
72
- # plugin
73
- #
74
- # File.read('Guardfile')
75
- # => "guard :rspec"
76
- #
77
- # Guard::Guardfile::Evaluator.new.guardfile_include?('rspec)
78
- # => true
79
- #
80
- # @param [String] plugin_name the name of the Guard
81
- # @return [Boolean] whether the Guard plugin has been declared
82
- #
83
- def guardfile_include?(plugin_name)
84
- regexp = /^guard\s*\(?\s*['":]#{ plugin_name }['"]?/
85
- _guardfile_contents_without_user_config.match(regexp)
86
- end
87
-
88
- # Gets the content of the `Guardfile` concatenated with the global
89
- # user configuration file.
90
- #
91
- # @example Programmatically get the content of the current Guardfile
92
- # Guard::Guardfile::Evaluator.new.guardfile_contents
93
- # => "guard :rspec"
94
- #
95
- # @return [String] the Guardfile content
96
- #
97
- def guardfile_contents
98
- config = File.read(_user_config_path) if File.exist?(_user_config_path)
99
- [_guardfile_contents_without_user_config, config].compact.join("\n")
100
- end
101
-
102
- private
103
-
104
- # Gets the content of the `Guardfile`.
105
- #
106
- # @return [String] the Guardfile content
107
- #
108
- def _guardfile_contents_without_user_config
109
- @guardfile_contents || ""
110
- end
111
-
112
- # Evaluates the content of the `Guardfile`.
113
- #
114
- # @param [String] contents the content to evaluate.
115
- #
116
- def _instance_eval_guardfile(contents)
117
- ::Guard::Dsl.new.instance_eval(contents, @guardfile_path || "", 1)
118
- rescue => ex
119
- ::Guard::UI.error "Invalid Guardfile, original error is:\n#{ $! }"
120
- raise ex
121
- end
122
-
123
- # Gets the content to evaluate and stores it into @guardfile_contents.
124
- #
125
- def _fetch_guardfile_contents
126
- _use_inline || _use_provided || _use_default
127
-
128
- return if _guardfile_contents_usable?
129
- ::Guard::UI.error "No Guard plugins found in Guardfile,"\
130
- " please add at least one."
131
- end
132
-
133
- # Use the provided inline Guardfile if provided.
134
- #
135
- def _use_inline
136
- source_from_option = @source.nil? && options[:guardfile_contents]
137
- inline = @source == :inline
138
-
139
- return false unless (source_from_option) || inline
140
-
141
- @source = :inline
142
- @guardfile_contents = options[:guardfile_contents]
143
-
144
- ::Guard::UI.info "Using inline Guardfile."
145
- true
146
- end
147
-
148
- # Try to use the provided Guardfile. Exits Guard if the Guardfile cannot
149
- # be found.
150
- #
151
- def _use_provided
152
- source_from_file = @source.nil? && options[:guardfile]
153
- return false unless source_from_file || (@source == :custom)
154
-
155
- @source = :custom
156
-
157
- options[:guardfile] = File.expand_path(options[:guardfile])
158
- if File.exist?(options[:guardfile])
159
- _read_guardfile(options[:guardfile])
160
- ::Guard::UI.info "Using Guardfile at #{ options[:guardfile] }."
161
- true
162
- else
163
- ::Guard::UI.error "No Guardfile exists at #{ options[:guardfile] }."
164
- exit 1
165
- end
166
-
167
- true
168
- end
169
-
170
- # Try to use one of the default Guardfiles (local or home Guardfile).
171
- # Exits Guard if no Guardfile is found.
172
- #
173
- def _use_default
174
- if guardfile_path = _find_default_guardfile
175
- @source = :default
176
- _read_guardfile(guardfile_path)
177
- else
178
- ::Guard::UI.error \
179
- "No Guardfile found, please create one with `guard init`."
180
- exit 1
181
- end
182
- end
183
-
184
- # Returns the first default Guardfile (either local or home Guardfile)
185
- # or nil otherwise.
186
- #
187
- def _find_default_guardfile
188
- [_local_guardfile_path, _home_guardfile_path].detect do |path|
189
- File.exist?(path)
190
- end
191
- end
192
-
193
- # Reads the current `Guardfile` content.
194
- #
195
- # @param [String] guardfile_path the path to the Guardfile
196
- #
197
- def _read_guardfile(guardfile_path)
198
- @guardfile_path = guardfile_path
199
- @guardfile_contents = File.read(guardfile_path)
200
- rescue => ex
201
- ::Guard::UI.error "Error reading file #{ guardfile_path }:"
202
- ::Guard::UI.error ex.inspect
203
- ::Guard::UI.error ex.backtrace
204
- exit 1
205
- end
206
-
207
- # Stops Guard and clear internal state
208
- # before the Guardfile will be re-evaluated.
209
- #
210
- def _before_reevaluate_guardfile
211
- ::Guard.runner.run(:stop)
212
- ::Guard.reset_groups
213
- ::Guard.reset_plugins
214
- ::Guard.reset_scope
215
- ::Guard::Notifier.clear_notifiers
216
- end
217
-
218
- # Starts Guard and notification and show a message
219
- # after the Guardfile has been re-evaluated.
220
- #
221
- def _after_reevaluate_guardfile
222
- ::Guard::Notifier.turn_on if ::Guard::Notifier.enabled?
223
-
224
- if !::Guard.send(:_pluginless_guardfile?)
225
- ::Guard::Notifier.notify(
226
- "No plugins found in Guardfile, please add at least one.",
227
- title: "Guard re-evaluate",
228
- image: :failed)
229
- else
230
- msg = "Guardfile has been re-evaluated."
231
- ::Guard::UI.info(msg)
232
- ::Guard::Notifier.notify(msg, title: "Guard re-evaluate")
233
-
234
- ::Guard.setup_scope
235
- ::Guard.runner.run(:start)
236
- end
237
- end
238
-
239
- # Tests if the current `Guardfile` content is usable.
240
- #
241
- # @return [Boolean] if the Guardfile is usable
242
- #
243
- def _guardfile_contents_usable?
244
- guardfile_contents && guardfile_contents =~ /guard/m
245
- end
246
-
247
- # The path to the `Guardfile` that is located at
248
- # the directory, where Guard has been started from.
249
- #
250
- # @return [String] the path to the local Guardfile
251
- #
252
- def _local_guardfile_path
253
- File.expand_path(File.join(Dir.pwd, "Guardfile"))
254
- end
255
-
256
- # The path to the `.Guardfile` that is located at
257
- # the users home directory.
258
- #
259
- # @return [String] the path to `~/.Guardfile`
260
- #
261
- def _home_guardfile_path
262
- File.expand_path(File.join("~", ".Guardfile"))
263
- end
264
-
265
- # The path to the user configuration `.guard.rb`
266
- # that is located at the users home directory.
267
- #
268
- # @return [String] the path to `~/.guard.rb`
269
- #
270
- def _user_config_path
271
- File.expand_path(File.join("~", ".guard.rb"))
272
- end
273
- end
274
- end
275
- end