guard 1.8.3 → 2.0.0.pre

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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +68 -10
  3. data/README.md +54 -33
  4. data/lib/guard.rb +133 -483
  5. data/lib/guard/cli.rb +78 -82
  6. data/lib/guard/commander.rb +121 -0
  7. data/lib/guard/commands/all.rb +1 -1
  8. data/lib/guard/commands/reload.rb +1 -1
  9. data/lib/guard/deprecated_methods.rb +59 -0
  10. data/lib/guard/deprecator.rb +107 -0
  11. data/lib/guard/dsl.rb +143 -329
  12. data/lib/guard/dsl_describer.rb +101 -57
  13. data/lib/guard/group.rb +27 -8
  14. data/lib/guard/guard.rb +25 -150
  15. data/lib/guard/guardfile.rb +35 -85
  16. data/lib/guard/guardfile/evaluator.rb +245 -0
  17. data/lib/guard/guardfile/generator.rb +89 -0
  18. data/lib/guard/interactor.rb +147 -163
  19. data/lib/guard/notifier.rb +83 -137
  20. data/lib/guard/notifiers/base.rb +220 -0
  21. data/lib/guard/notifiers/emacs.rb +39 -37
  22. data/lib/guard/notifiers/file_notifier.rb +29 -25
  23. data/lib/guard/notifiers/gntp.rb +68 -75
  24. data/lib/guard/notifiers/growl.rb +49 -52
  25. data/lib/guard/notifiers/growl_notify.rb +51 -56
  26. data/lib/guard/notifiers/libnotify.rb +41 -48
  27. data/lib/guard/notifiers/notifysend.rb +58 -38
  28. data/lib/guard/notifiers/rb_notifu.rb +54 -54
  29. data/lib/guard/notifiers/terminal_notifier.rb +48 -36
  30. data/lib/guard/notifiers/terminal_title.rb +23 -19
  31. data/lib/guard/notifiers/tmux.rb +110 -93
  32. data/lib/guard/options.rb +21 -0
  33. data/lib/guard/plugin.rb +66 -0
  34. data/lib/guard/plugin/base.rb +178 -0
  35. data/lib/guard/plugin/hooker.rb +123 -0
  36. data/lib/guard/plugin_util.rb +158 -0
  37. data/lib/guard/rake_task.rb +47 -0
  38. data/lib/guard/runner.rb +62 -82
  39. data/lib/guard/setuper.rb +248 -0
  40. data/lib/guard/ui.rb +24 -80
  41. data/lib/guard/ui/colors.rb +60 -0
  42. data/lib/guard/version.rb +1 -2
  43. data/lib/guard/watcher.rb +30 -30
  44. data/man/guard.1 +4 -4
  45. data/man/guard.1.html +6 -4
  46. metadata +25 -11
  47. data/lib/guard/hook.rb +0 -120
@@ -1,5 +1,7 @@
1
1
  require 'lumberjack'
2
2
 
3
+ require 'guard/ui/colors'
4
+
3
5
  module Guard
4
6
 
5
7
  # The UI class helps to format messages for the user. Everything that is logged
@@ -10,6 +12,7 @@ module Guard
10
12
  # processing, please just write it to STDOUT with `puts`.
11
13
  #
12
14
  module UI
15
+ include Colors
13
16
 
14
17
  class << self
15
18
 
@@ -17,8 +20,8 @@ module Guard
17
20
  #
18
21
  def logger
19
22
  @logger ||= begin
20
- options = self.options.dup
21
- Lumberjack::Logger.new(options.delete(:device) || $stderr, options)
23
+ opts = options.marshal_dump
24
+ Lumberjack::Logger.new(opts.delete(:device) { $stderr }, opts)
22
25
  end
23
26
  end
24
27
 
@@ -27,7 +30,7 @@ module Guard
27
30
  # @return [Hash] the logger options
28
31
  #
29
32
  def options
30
- @options ||= { :level => :info, :template => ':time - :severity - :message', :time_format => '%H:%M:%S' }
33
+ @options ||= ::Guard::Options.new(level: :info, template: ':time - :severity - :message', time_format: '%H:%M:%S')
31
34
  end
32
35
 
33
36
  # Set the logger options
@@ -38,7 +41,7 @@ module Guard
38
41
  # @option options [String] time_format the time format
39
42
  #
40
43
  def options=(options)
41
- @options = options
44
+ @options = ::Guard::Options.new(options)
42
45
  end
43
46
 
44
47
  # Show an info message.
@@ -47,10 +50,10 @@ module Guard
47
50
  # @option options [Boolean] reset whether to clean the output before
48
51
  # @option options [String] plugin manually define the calling plugin
49
52
  #
50
- def info(message, options = { })
53
+ def info(message, options = {})
51
54
  filter(options[:plugin]) do |plugin|
52
55
  reset_line if options[:reset]
53
- self.logger.info(message, plugin)
56
+ logger.info(message, plugin)
54
57
  end
55
58
  end
56
59
 
@@ -60,10 +63,10 @@ module Guard
60
63
  # @option options [Boolean] reset whether to clean the output before
61
64
  # @option options [String] plugin manually define the calling plugin
62
65
  #
63
- def warning(message, options = { })
66
+ def warning(message, options = {})
64
67
  filter(options[:plugin]) do |plugin|
65
68
  reset_line if options[:reset]
66
- self.logger.warn(color(message, :yellow), plugin)
69
+ logger.warn(color(message, :yellow), plugin)
67
70
  end
68
71
  end
69
72
 
@@ -73,10 +76,10 @@ module Guard
73
76
  # @option options [Boolean] reset whether to clean the output before
74
77
  # @option options [String] plugin manually define the calling plugin
75
78
  #
76
- def error(message, options = { })
79
+ def error(message, options = {})
77
80
  filter(options[:plugin]) do |plugin|
78
81
  reset_line if options[:reset]
79
- self.logger.error(color(message, :red), plugin)
82
+ logger.error(color(message, :red), plugin)
80
83
  end
81
84
  end
82
85
 
@@ -87,10 +90,12 @@ module Guard
87
90
  # @option options [Boolean] reset whether to clean the output before
88
91
  # @option options [String] plugin manually define the calling plugin
89
92
  #
90
- def deprecation(message, options = { })
93
+ def deprecation(message, options = {})
94
+ return unless ::Guard.options.show_deprecations
95
+
91
96
  filter(options[:plugin]) do |plugin|
92
97
  reset_line if options[:reset]
93
- self.logger.warn(color(message, :yellow), plugin)
98
+ logger.warn(color(message, :yellow), plugin)
94
99
  end
95
100
  end
96
101
 
@@ -100,10 +105,10 @@ module Guard
100
105
  # @option options [Boolean] reset whether to clean the output before
101
106
  # @option options [String] plugin manually define the calling plugin
102
107
  #
103
- def debug(message, options = { })
108
+ def debug(message, options = {})
104
109
  filter(options[:plugin]) do |plugin|
105
110
  reset_line if options[:reset]
106
- self.logger.debug(color(message, :yellow), plugin)
111
+ logger.debug(color(message, :yellow), plugin)
107
112
  end
108
113
  end
109
114
 
@@ -116,7 +121,7 @@ module Guard
116
121
  # Clear the output if clearable.
117
122
  #
118
123
  def clear(options = {})
119
- if ::Guard.options[:clear] && (@clearable || options[:force])
124
+ if ::Guard.options.clear && (@clearable || options[:force])
120
125
  @clearable = false
121
126
  system('clear;')
122
127
  end
@@ -142,8 +147,8 @@ module Guard
142
147
  groups = ::Guard.scope[:groups] || []
143
148
  end
144
149
 
145
- scope_message ||= plugins.join(',') unless plugins.empty?
146
- scope_message ||= groups.join(',') unless groups.empty?
150
+ scope_message ||= plugins.map(&:title).join(', ') unless plugins.empty?
151
+ scope_message ||= groups.map(&:title).join(', ') unless groups.empty?
147
152
  scope_message ||= 'all'
148
153
 
149
154
  info "#{ action } #{ scope_message }"
@@ -159,8 +164,8 @@ module Guard
159
164
  # @yieldparam [String] param the calling plugin name
160
165
  #
161
166
  def filter(plugin)
162
- only = self.options[:only]
163
- except = self.options[:except]
167
+ only = options.only
168
+ except = options.except
164
169
  plugin = plugin || calling_plugin_name
165
170
 
166
171
  if (!only && !except) || (only && only.match(plugin)) || (except && !except.match(plugin))
@@ -179,16 +184,6 @@ module Guard
179
184
  name ? name[1].split('/').map { |part| part.split(/[^a-z0-9]/i).map { |word| word.capitalize }.join }.join('::') : 'Guard'
180
185
  end
181
186
 
182
- # Reset a color sequence.
183
- #
184
- # @deprecated
185
- # @param [String] text the text
186
- #
187
- def reset_color(text)
188
- deprecation('UI.reset_color(text) is deprecated, please use color(text, ' ') instead.')
189
- color(text, '')
190
- end
191
-
192
187
  # Checks if color output can be enabled.
193
188
  #
194
189
  # @return [Boolean] whether color is enabled or not
@@ -243,56 +238,5 @@ module Guard
243
238
 
244
239
  end
245
240
 
246
- # Brighten the color
247
- ANSI_ESCAPE_BRIGHT = '1'
248
-
249
- # Black foreground color
250
- ANSI_ESCAPE_BLACK = '30'
251
-
252
- # Red foreground color
253
- ANSI_ESCAPE_RED = '31'
254
-
255
- # Green foreground color
256
- ANSI_ESCAPE_GREEN = '32'
257
-
258
- # Yellow foreground color
259
- ANSI_ESCAPE_YELLOW = '33'
260
-
261
- # Blue foreground color
262
- ANSI_ESCAPE_BLUE = '34'
263
-
264
- # Magenta foreground color
265
- ANSI_ESCAPE_MAGENTA = '35'
266
-
267
- # Cyan foreground color
268
- ANSI_ESCAPE_CYAN = '36'
269
-
270
- # White foreground color
271
- ANSI_ESCAPE_WHITE = '37'
272
-
273
- # Black background color
274
- ANSI_ESCAPE_BGBLACK = '40'
275
-
276
- # Red background color
277
- ANSI_ESCAPE_BGRED = '41'
278
-
279
- # Green background color
280
- ANSI_ESCAPE_BGGREEN = '42'
281
-
282
- # Yellow background color
283
- ANSI_ESCAPE_BGYELLOW = '43'
284
-
285
- # Blue background color
286
- ANSI_ESCAPE_BGBLUE = '44'
287
-
288
- # Magenta background color
289
- ANSI_ESCAPE_BGMAGENTA = '45'
290
-
291
- # Cyan background color
292
- ANSI_ESCAPE_BGCYAN = '46'
293
-
294
- # White background color
295
- ANSI_ESCAPE_BGWHITE = '47'
296
-
297
241
  end
298
242
  end
@@ -0,0 +1,60 @@
1
+ module Guard
2
+ module UI
3
+
4
+ module Colors
5
+
6
+ # Brighten the color
7
+ ANSI_ESCAPE_BRIGHT = '1'
8
+
9
+ # Black foreground color
10
+ ANSI_ESCAPE_BLACK = '30'
11
+
12
+ # Red foreground color
13
+ ANSI_ESCAPE_RED = '31'
14
+
15
+ # Green foreground color
16
+ ANSI_ESCAPE_GREEN = '32'
17
+
18
+ # Yellow foreground color
19
+ ANSI_ESCAPE_YELLOW = '33'
20
+
21
+ # Blue foreground color
22
+ ANSI_ESCAPE_BLUE = '34'
23
+
24
+ # Magenta foreground color
25
+ ANSI_ESCAPE_MAGENTA = '35'
26
+
27
+ # Cyan foreground color
28
+ ANSI_ESCAPE_CYAN = '36'
29
+
30
+ # White foreground color
31
+ ANSI_ESCAPE_WHITE = '37'
32
+
33
+ # Black background color
34
+ ANSI_ESCAPE_BGBLACK = '40'
35
+
36
+ # Red background color
37
+ ANSI_ESCAPE_BGRED = '41'
38
+
39
+ # Green background color
40
+ ANSI_ESCAPE_BGGREEN = '42'
41
+
42
+ # Yellow background color
43
+ ANSI_ESCAPE_BGYELLOW = '43'
44
+
45
+ # Blue background color
46
+ ANSI_ESCAPE_BGBLUE = '44'
47
+
48
+ # Magenta background color
49
+ ANSI_ESCAPE_BGMAGENTA = '45'
50
+
51
+ # Cyan background color
52
+ ANSI_ESCAPE_BGCYAN = '46'
53
+
54
+ # White background color
55
+ ANSI_ESCAPE_BGWHITE = '47'
56
+
57
+ end
58
+
59
+ end
60
+ end
@@ -1,4 +1,3 @@
1
1
  module Guard
2
- # The current gem version of Guard
3
- VERSION = '1.8.3'
2
+ VERSION = '2.0.0.pre'
4
3
  end
@@ -1,19 +1,22 @@
1
+ require 'guard/ui'
2
+
1
3
  module Guard
2
4
 
3
- # The watcher defines a RegExp that will be matched against file system modifications.
4
- # When a watcher matches a change, an optional action block is executed to enable
5
- # processing the file system change result.
5
+ # The watcher defines a RegExp that will be matched against file system
6
+ # modifications.
7
+ # When a watcher matches a change, an optional action block is executed to
8
+ # enable processing the file system change result.
6
9
  #
7
10
  class Watcher
8
11
 
9
- require 'guard/ui'
10
-
11
12
  attr_accessor :pattern, :action
12
13
 
13
- # Initialize a file watcher.
14
+ # Initializes a file watcher.
14
15
  #
15
- # @param [String, Regexp] pattern the pattern to be watched by the Guard plugin
16
- # @param [Block] action the action to execute before passing the result to the Guard plugin
16
+ # @param [String, Regexp] pattern the pattern to be watched by the Guard
17
+ # plugin
18
+ # @param [Block] action the action to execute before passing the result to
19
+ # the Guard plugin
17
20
  #
18
21
  def initialize(pattern, action = nil)
19
22
  @pattern, @action = pattern, action
@@ -36,14 +39,15 @@ module Guard
36
39
  end
37
40
  end
38
41
 
39
- # Finds the files that matches a Guard.
42
+ # Finds the files that matches a Guard plugin.
40
43
  #
41
- # @param [Guard::Guard] guard the Guard plugin which watchers are used
44
+ # @param [Guard::Plugin] guard the Guard plugin which watchers are used
42
45
  # @param [Array<String>] files the changed files
43
46
  # @return [Array<Object>] the matched watcher response
44
47
  #
45
48
  def self.match_files(guard, files)
46
49
  return [] if files.empty?
50
+
47
51
  guard.watchers.inject([]) do |paths, watcher|
48
52
  files.each do |file|
49
53
  if matches = watcher.match(file)
@@ -64,31 +68,35 @@ module Guard
64
68
  end
65
69
  end
66
70
 
67
- # Test if a file would be matched by any of the Guard plugin watchers.
71
+ # Tests if a file would be matched by any of the Guard plugin watchers.
68
72
  #
69
- # @param [Array<Guard::Guard>] guards the Guard plugins to use the watchers from
73
+ # @param [Array<Guard::Plugin>] plugins the Guard plugins to use the
74
+ # watchers from
70
75
  # @param [Array<String>] files the files to test
71
76
  # @return [Boolean] Whether a file matches
72
77
  #
73
- def self.match_files?(guards, files)
74
- guards.any? do |guard|
75
- guard.watchers.any? do |watcher|
78
+ def self.match_files?(plugins, files)
79
+ plugins.any? do |plugin|
80
+ plugin.watchers.any? do |watcher|
76
81
  files.any? { |file| watcher.match(file) }
77
82
  end
78
83
  end
79
84
  end
80
85
 
81
- # @deprecated Use .match instead
86
+ # Tests if any of the files is the Guardfile.
82
87
  #
83
- def match_file?(file)
84
- ::Guard::UI.info "Guard::Watcher.match_file? is deprecated, please use Guard::Watcher.match instead."
85
- match(file)
88
+ # @param [Array<String>] files the files to test
89
+ # @return [Boolean] whether one of these files is the Guardfile
90
+ #
91
+ def self.match_guardfile?(files)
92
+ files.any? { |file| "#{ Dir.pwd }/#{ file }" == ::Guard.evaluator.guardfile_path }
86
93
  end
87
94
 
88
95
  # Test the watchers pattern against a file.
89
96
  #
90
97
  # @param [String] file the file to test
91
- # @return [Array<String>] an array of matches (or containing a single path if the pattern is a string)
98
+ # @return [Array<String>] an array of matches (or containing a single path
99
+ # if the pattern is a string)
92
100
  #
93
101
  def match(file)
94
102
  f = file
@@ -105,18 +113,10 @@ module Guard
105
113
  end
106
114
  end
107
115
 
108
- # Test if any of the files is the Guardfile.
109
- #
110
- # @param [Array<String>] files the files to test
111
- # @return [Boolean] whether one of these files is the Guardfile
112
- #
113
- def self.match_guardfile?(files)
114
- files.any? { |file| "#{ Dir.pwd }/#{ file }" == Dsl.guardfile_path }
115
- end
116
-
117
116
  # Executes a watcher action.
118
117
  #
119
- # @param [String, MatchData] matches the matched path or the match from the Regex
118
+ # @param [String, MatchData] matches the matched path or the match from the
119
+ # Regex
120
120
  # @return [String] the final paths
121
121
  #
122
122
  def call_action(matches)
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "GUARD" "1" "December 2012" "" ""
4
+ .TH "GUARD" "1" "September 2013" "" ""
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBguard\fR \- Guard keeps an eye on your file modifications\.
@@ -98,11 +98,11 @@ Thibaud Guillaume\-Gentil is the main author\.
98
98
  .P
99
99
  A list of contributors based on all commits can be found here: https://github\.com/guard/guard/contributors
100
100
  .
101
- .P
102
- For an exhaustive list of all the contributors, please see the CHANGELOG: https://github\.com/guard/guard/blob/master/CHANGELOG\.md
101
+ .SH "CHANGELOG"
102
+ The changelog can be found at: https://github\.com/guard/guard/blob/master/CHANGELOG\.md
103
103
  .
104
104
  .P
105
105
  This manual has been written by Remy Coutable\.
106
106
  .
107
107
  .SH "WWW"
108
- https://github\.com/guard/guard
108
+ http://guardgem\.org/
@@ -59,6 +59,7 @@
59
59
  <a href="#COMMANDS">COMMANDS</a>
60
60
  <a href="#EXAMPLES">EXAMPLES</a>
61
61
  <a href="#AUTHORS-CONTRIBUTORS">AUTHORS / CONTRIBUTORS</a>
62
+ <a href="#CHANGELOG">CHANGELOG</a>
62
63
  <a href="#WWW">WWW</a>
63
64
  </div>
64
65
 
@@ -173,19 +174,20 @@ For instance to initialize guard-rspec, run <code>guard init rspec</code>.</p>
173
174
  <p>A list of contributors based on all commits can be found here:
174
175
  https://github.com/guard/guard/contributors</p>
175
176
 
176
- <p>For an exhaustive list of all the contributors, please see the CHANGELOG:
177
- https://github.com/guard/guard/blob/master/CHANGELOG.md</p>
177
+ <h2 id="CHANGELOG">CHANGELOG</h2>
178
+
179
+ <p>The changelog can be found at: https://github.com/guard/guard/blob/master/CHANGELOG.md</p>
178
180
 
179
181
  <p>This manual has been written by Remy Coutable.</p>
180
182
 
181
183
  <h2 id="WWW">WWW</h2>
182
184
 
183
- <p>https://github.com/guard/guard</p>
185
+ <p>http://guardgem.org/</p>
184
186
 
185
187
 
186
188
  <ol class='man-decor man-foot man foot'>
187
189
  <li class='tl'></li>
188
- <li class='tc'>December 2012</li>
190
+ <li class='tc'>September 2013</li>
189
191
  <li class='tr'>guard(1)</li>
190
192
  </ol>
191
193