guard 2.6.1 → 2.7.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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +73 -58
  3. data/bin/guard +2 -2
  4. data/lib/guard.rb +64 -59
  5. data/lib/guard/cli.rb +66 -60
  6. data/lib/guard/cli.rb.orig +215 -0
  7. data/lib/guard/commander.rb +45 -69
  8. data/lib/guard/commands/all.rb +21 -19
  9. data/lib/guard/commands/change.rb +17 -22
  10. data/lib/guard/commands/notification.rb +15 -16
  11. data/lib/guard/commands/pause.rb +14 -15
  12. data/lib/guard/commands/reload.rb +19 -20
  13. data/lib/guard/commands/scope.rb +23 -19
  14. data/lib/guard/commands/show.rb +13 -16
  15. data/lib/guard/deprecated_methods.rb +6 -10
  16. data/lib/guard/deprecator.rb +52 -37
  17. data/lib/guard/dsl.rb +55 -33
  18. data/lib/guard/dsl_describer.rb +83 -31
  19. data/lib/guard/dsl_describer.rb.orig +184 -0
  20. data/lib/guard/group.rb +7 -6
  21. data/lib/guard/guard.rb +4 -4
  22. data/lib/guard/guard.rb.orig +42 -0
  23. data/lib/guard/guardfile.rb +12 -13
  24. data/lib/guard/guardfile/evaluator.rb +77 -55
  25. data/lib/guard/guardfile/evaluator.rb.orig +275 -0
  26. data/lib/guard/guardfile/generator.rb +25 -20
  27. data/lib/guard/interactor.rb +52 -293
  28. data/lib/guard/interactor.rb.orig +85 -0
  29. data/lib/guard/jobs/base.rb +21 -0
  30. data/lib/guard/jobs/pry_wrapper.rb +290 -0
  31. data/lib/guard/jobs/pry_wrapper.rb.orig +293 -0
  32. data/lib/guard/jobs/sleep.rb +25 -0
  33. data/lib/guard/notifier.rb +42 -39
  34. data/lib/guard/notifiers/base.rb +25 -24
  35. data/lib/guard/notifiers/emacs.rb +30 -24
  36. data/lib/guard/notifiers/file_notifier.rb +3 -7
  37. data/lib/guard/notifiers/gntp.rb +22 -22
  38. data/lib/guard/notifiers/growl.rb +16 -15
  39. data/lib/guard/notifiers/libnotify.rb +7 -10
  40. data/lib/guard/notifiers/notifysend.rb +15 -14
  41. data/lib/guard/notifiers/rb_notifu.rb +8 -10
  42. data/lib/guard/notifiers/terminal_notifier.rb +15 -11
  43. data/lib/guard/notifiers/terminal_title.rb +4 -8
  44. data/lib/guard/notifiers/tmux.rb +104 -71
  45. data/lib/guard/options.rb +1 -5
  46. data/lib/guard/plugin.rb +1 -3
  47. data/lib/guard/plugin/base.rb +12 -9
  48. data/lib/guard/plugin/hooker.rb +1 -5
  49. data/lib/guard/plugin_util.rb +46 -25
  50. data/lib/guard/plugin_util.rb.orig +178 -0
  51. data/lib/guard/rake_task.rb +4 -7
  52. data/lib/guard/reevaluator.rb +13 -0
  53. data/lib/guard/runner.rb +50 -78
  54. data/lib/guard/runner.rb.orig +200 -0
  55. data/lib/guard/setuper.rb +199 -130
  56. data/lib/guard/setuper.rb.orig +348 -0
  57. data/lib/guard/sheller.rb +107 -0
  58. data/lib/guard/tags +367 -0
  59. data/lib/guard/ui.rb +50 -38
  60. data/lib/guard/ui.rb.orig +254 -0
  61. data/lib/guard/ui/colors.rb +17 -21
  62. data/lib/guard/version.rb +1 -1
  63. data/lib/guard/version.rb.orig +3 -0
  64. data/lib/guard/watcher.rb +49 -62
  65. metadata +21 -4
  66. data/lib/guard/notifiers/growl_notify.rb +0 -93
@@ -1,12 +1,10 @@
1
- require 'guard/notifiers/base'
1
+ require "guard/notifiers/base"
2
2
 
3
3
  module Guard
4
4
  module Notifier
5
-
6
5
  # Shows system notifications in the terminal title bar.
7
6
  #
8
7
  class TerminalTitle < Base
9
-
10
8
  # Shows a system notification.
11
9
  #
12
10
  # @param [Hash] opts additional notification library options
@@ -18,18 +16,16 @@ module Guard
18
16
  def notify(message, opts = {})
19
17
  super
20
18
 
21
- first_line = message.sub(/^\n/, '').sub(/\n.*/m, '')
19
+ first_line = message.sub(/^\n/, "").sub(/\n.*/m, "")
22
20
 
23
- puts "\e]2;[#{ opts[:title] }] #{ first_line }\a"
21
+ STDOUT.puts "\e]2;[#{ opts[:title] }] #{ first_line }\a"
24
22
  end
25
23
 
26
24
  # Clears the terminal title
27
25
  #
28
26
  def self.turn_off
29
- puts "\e]2;\a"
27
+ STDOUT.puts "\e]2;\a"
30
28
  end
31
-
32
29
  end
33
-
34
30
  end
35
31
  end
@@ -1,8 +1,7 @@
1
- require 'guard/notifiers/base'
1
+ require "guard/notifiers/base"
2
2
 
3
3
  module Guard
4
4
  module Notifier
5
-
6
5
  # Changes the color of the Tmux status bar and optionally
7
6
  # shows messages in the status bar.
8
7
  #
@@ -16,29 +15,31 @@ module Guard
16
15
  # notification :tmux, color_location: 'status-right-bg'
17
16
  #
18
17
  class Tmux < Base
19
-
20
18
  # Default options for the tmux notifications.
21
19
  DEFAULTS = {
22
- client: 'tmux',
23
- tmux_environment: 'TMUX',
24
- success: 'green',
25
- failed: 'red',
26
- pending: 'yellow',
27
- default: 'green',
20
+ client: "tmux",
21
+ tmux_environment: "TMUX",
22
+ success: "green",
23
+ failed: "red",
24
+ pending: "yellow",
25
+ default: "green",
28
26
  timeout: 5,
29
27
  display_message: false,
30
- default_message_format: '%s - %s',
31
- default_message_color: 'white',
28
+ default_message_format: "%s - %s",
29
+ default_message_color: "white",
32
30
  display_on_all_clients: false,
33
31
  display_title: false,
34
- default_title_format: '%s - %s',
35
- line_separator: ' - ',
32
+ default_title_format: "%s - %s",
33
+ line_separator: " - ",
36
34
  change_color: true,
37
- color_location: 'status-left-bg'
35
+ color_location: "status-left-bg"
38
36
  }
39
37
 
38
+ ERROR_NOT_INSIDE_SESSION = "The :tmux notifier runs only on when Guard"\
39
+ " is executed inside of a tmux session."
40
+
40
41
  def self.available?(opts = {})
41
- super and _register!(opts)
42
+ super && _register!(opts)
42
43
  end
43
44
 
44
45
  # @private
@@ -57,11 +58,12 @@ module Guard
57
58
  # @return [Boolean] whether or not a TMUX environment is available
58
59
  #
59
60
  def self._register!(opts)
61
+ @options_stored = false
60
62
  if _tmux_environment_available?(opts)
61
63
  true
62
64
  else
63
65
  unless opts[:silent]
64
- ::Guard::UI.error 'The :tmux notifier runs only on when Guard is executed inside of a tmux session.'
66
+ ::Guard::UI.error ERROR_NOT_INSIDE_SESSION
65
67
  end
66
68
  false
67
69
  end
@@ -86,8 +88,8 @@ module Guard
86
88
  # @option opts [String] image the path to the notification image
87
89
  # @option opts [Boolean] change_color whether to show a color
88
90
  # notification
89
- # @option opts [String,Array] color_location the location where to draw the
90
- # color notification
91
+ # @option opts [String,Array] color_location the location where to draw
92
+ # the color notification
91
93
  # @option opts [Boolean] display_message whether to display a message
92
94
  # or not
93
95
  # @option opts [Boolean] display_on_all_clients whether to display a
@@ -98,11 +100,13 @@ module Guard
98
100
  opts.delete(:image)
99
101
 
100
102
  if opts.fetch(:change_color, DEFAULTS[:change_color])
101
- color_locations = Array(opts.fetch(:color_location, DEFAULTS[:color_location]))
103
+ options = opts.fetch(:color_location, DEFAULTS[:color_location])
104
+ color_locations = Array(options)
102
105
  color = tmux_color(opts[:type], opts)
103
106
 
104
107
  color_locations.each do |color_location|
105
- _run_client "set","#{_quiet_option}#{ color_location } #{ color }"
108
+ _run_client "set", "#{self.class._quiet_option}"\
109
+ "#{color_location} #{color}"
106
110
  end
107
111
  end
108
112
 
@@ -113,9 +117,8 @@ module Guard
113
117
  display_title(type, title, message, opts)
114
118
  end
115
119
 
116
- if opts.fetch(:display_message, DEFAULTS[:display_message])
117
- display_message(type, title, message, opts)
118
- end
120
+ return unless opts.fetch(:display_message, DEFAULTS[:display_message])
121
+ display_message(type, title, message, opts)
119
122
  end
120
123
 
121
124
  # Displays a message in the title bar of the terminal.
@@ -133,11 +136,15 @@ module Guard
133
136
  # formatter when no format per type is defined.
134
137
  #
135
138
  def display_title(type, title, message, opts = {})
136
- title_format = opts.fetch("#{ type }_title_format".to_sym, opts.fetch(:default_title_format, DEFAULTS[:default_title_format]))
139
+ format = "#{type}_title_format".to_sym
140
+ defaults = DEFAULTS[:default_title_format]
141
+ options = opts.fetch(:default_title_format, defaults)
142
+ title_format = opts.fetch(format, options)
137
143
  teaser_message = message.split("\n").first
138
144
  display_title = title_format % [title, teaser_message]
139
145
 
140
- _run_client "set-option", "#{_quiet_option}set-titles-string '#{ display_title }'"
146
+ _run_client "set-option", "#{self.class._quiet_option}"\
147
+ "set-titles-string '#{display_title}'"
141
148
  end
142
149
 
143
150
  # Displays a message in the status bar of tmux.
@@ -169,8 +176,16 @@ module Guard
169
176
  # line-break.
170
177
  #
171
178
  def display_message(type, title, message, opts = {})
172
- message_format = opts.fetch("#{ type }_message_format".to_sym, opts.fetch(:default_message_format, DEFAULTS[:default_message_format]))
173
- message_color = opts.fetch("#{ type }_message_color".to_sym, opts.fetch(:default_message_color, DEFAULTS[:default_message_color]))
179
+ default_format = DEFAULTS[:default_message_format]
180
+ default_format = opts.fetch(:default_message_format, default_format)
181
+ format = "#{type}_message_format".to_sym
182
+ message_format = opts.fetch(format, default_format)
183
+
184
+ default_color = DEFAULTS[:default_message_color]
185
+ default_color = opts.fetch(:default_message_color, default_color)
186
+ color = "#{type}_message_color".to_sym
187
+ message_color = opts.fetch(color, default_color)
188
+
174
189
  display_time = opts.fetch(:timeout, DEFAULTS[:timeout])
175
190
  separator = opts.fetch(:line_separator, DEFAULTS[:line_separator])
176
191
 
@@ -178,10 +193,15 @@ module Guard
178
193
  formatted_message = message.split("\n").join(separator)
179
194
  display_message = message_format % [title, formatted_message]
180
195
 
181
- _run_client "set", "#{_quiet_option}display-time #{ display_time * 1000 }"
182
- _run_client "set", "#{_quiet_option}message-fg #{ message_color }"
183
- _run_client "set", "#{_quiet_option}message-bg #{ color }"
184
- _run_client "display-message", "'#{ display_message }'"
196
+ _run_client(
197
+ "set",
198
+ "#{self.class._quiet_option}display-time #{display_time * 1000}")
199
+
200
+ _run_client "set", "#{self.class._quiet_option}"\
201
+ "message-fg #{message_color}"
202
+ _run_client "set", "#{self.class._quiet_option}"\
203
+ "message-bg #{color}"
204
+ _run_client "display-message", "'#{display_message}'"
185
205
  end
186
206
 
187
207
  # Get the Tmux color for the notification type.
@@ -192,9 +212,8 @@ module Guard
192
212
  #
193
213
  def tmux_color(type, opts = {})
194
214
  type = type.to_sym
195
- type = :default unless [:success, :failed, :pending].include?(type)
196
215
 
197
- opts.fetch(type, DEFAULTS[type])
216
+ opts[type] || DEFAULTS[type] || opts[:default] || DEFAULTS[:default]
198
217
  end
199
218
 
200
219
  # Notification starting, save the current Tmux settings
@@ -205,11 +224,7 @@ module Guard
205
224
  _reset_options_store
206
225
 
207
226
  _clients.each do |client|
208
- options_store[client] ||= {}
209
- `#{ DEFAULTS[:client] } show -t #{ client }`.each_line do |line|
210
- option, _, setting = line.chomp.partition(' ')
211
- @options_store[client][option] = setting
212
- end
227
+ @options_store[client].merge!(_options_for_client(client))
213
228
  end
214
229
 
215
230
  @options_stored = true
@@ -224,11 +239,14 @@ module Guard
224
239
  if @options_stored
225
240
  @options_store.each do |client, options|
226
241
  options.each do |key, value|
227
- if value
228
- `#{ DEFAULTS[:client] } set -t #{ client } -q #{ key } #{ value }`
229
- else
230
- `#{ DEFAULTS[:client] } set -t #{ client } -q -u #{ key }`
231
- end
242
+ args = [
243
+ DEFAULTS[:client], "set", "-t",
244
+ client, _quiet_option.strip
245
+ ]
246
+ args << "-u" unless value
247
+ args << key
248
+ args << value if value
249
+ Sheller.run(args.join(" "))
232
250
  end
233
251
  end
234
252
  _reset_options_store
@@ -241,35 +259,52 @@ module Guard
241
259
 
242
260
  private
243
261
 
244
- def system(args)
245
- args += " >#{ DEV_NULL } 2>&1" if ENV['GUARD_ENV'] == 'test'
246
- super
247
- end
248
-
249
262
  def self._clients
250
- ttys = `#{ DEFAULTS[:client] } list-clients -F '\#{client_tty}'`.split(/\n/)
251
- ttys.delete('(null)') #if user is running 'tmux -C' remove this client from list
263
+ args = [DEFAULTS[:client], "list-clients", "-F", "'\#{client_tty}'"]
264
+ ttys = Sheller.stdout(args.join(" "))
265
+ ttys = ttys.split(/\n/)
266
+
267
+ # if user is running 'tmux -C' remove this client from list
268
+ ttys.delete("(null)")
269
+
252
270
  ttys
253
271
  end
254
272
 
273
+ def self._options_for_client(client)
274
+ options = {}
275
+
276
+ lines = Sheller.stdout("#{DEFAULTS[:client]} show -t #{client}")
277
+
278
+ lines.each_line do |line|
279
+ option, _, setting = line.chomp.partition(" ")
280
+ options[option] = setting
281
+ end
282
+
283
+ options
284
+ end
285
+
255
286
  def _clients
256
287
  self.class._clients
257
288
  end
258
289
 
259
290
  def _run_client(cmd, args)
260
- if @options.fetch(:display_on_all_clients, DEFAULTS[:display_on_all_clients])
261
- _clients.each do |client|
262
- system("#{ DEFAULTS[:client] } #{ cmd } #{ _client_cmd_flag(cmd) } #{ client.strip } #{ args }")
263
- end
264
- else
265
- system("#{ DEFAULTS[:client] } #{ cmd } #{ args }")
291
+ default = DEFAULTS[:display_on_all_clients]
292
+ all_clients = @options.fetch(:display_on_all_clients, default)
293
+ clients = all_clients ? _clients : [nil]
294
+ clients.each do |client|
295
+ cmd_args = if client
296
+ "#{_client_cmd_flag(cmd)} #{client.strip} #{args}"
297
+ else
298
+ args
299
+ end
300
+ Sheller.run("#{DEFAULTS[:client]} #{cmd} #{cmd_args}")
266
301
  end
267
302
  end
268
303
 
269
304
  def _client_cmd_flag(cmd)
270
305
  case cmd
271
- when 'set', 'set-option' then '-t'
272
- when 'display-message' then '-c'
306
+ when "set", "set-option" then "-t"
307
+ when "display-message" then "-c"
273
308
  end
274
309
  end
275
310
 
@@ -281,26 +316,24 @@ module Guard
281
316
 
282
317
  _clients.each do |client|
283
318
  @options_store[client] = {
284
- 'status-left-bg' => nil,
285
- 'status-right-bg' => nil,
286
- 'status-left-fg' => nil,
287
- 'status-right-fg' => nil,
288
- 'message-bg' => nil,
289
- 'message-fg' => nil,
290
- 'display-time' => nil
319
+ "status-left-bg" => nil,
320
+ "status-right-bg" => nil,
321
+ "status-left-fg" => nil,
322
+ "status-right-fg" => nil,
323
+ "message-bg" => nil,
324
+ "message-fg" => nil,
325
+ "display-time" => nil
291
326
  }
292
327
  end
293
328
  end
294
329
 
295
- def _tmux_version
296
- @tmux_version ||= `tmux -V`.chomp.gsub(/[^0-9.]/, '').to_f
330
+ def self._tmux_version
331
+ @@tmux_version ||= Float(Sheller.stdout("tmux -V")[/\d+\.\d+/])
297
332
  end
298
333
 
299
- def _quiet_option
300
- '-q ' if _tmux_version >= 1.7
334
+ def self._quiet_option
335
+ "-q " if _tmux_version >= 1.7
301
336
  end
302
-
303
337
  end
304
-
305
338
  end
306
339
  end
data/lib/guard/options.rb CHANGED
@@ -1,11 +1,9 @@
1
- require 'thor/core_ext/hash_with_indifferent_access'
1
+ require "thor/core_ext/hash_with_indifferent_access"
2
2
 
3
3
  module Guard
4
-
5
4
  # A class that holds options. Can be instantiated with default options.
6
5
  #
7
6
  class Options < Thor::CoreExt::HashWithIndifferentAccess
8
-
9
7
  # Initializes an Guard::Options object. `default_opts` is merged into
10
8
  # `opts`.
11
9
  #
@@ -15,7 +13,5 @@ module Guard
15
13
  def initialize(opts = {}, default_opts = {})
16
14
  super(default_opts.merge(opts || {}))
17
15
  end
18
-
19
16
  end
20
-
21
17
  end
data/lib/guard/plugin.rb CHANGED
@@ -1,7 +1,6 @@
1
- require 'guard/plugin/base'
1
+ require "guard/plugin/base"
2
2
 
3
3
  module Guard
4
-
5
4
  # Base class from which every Guard plugin implementation must inherit.
6
5
  #
7
6
  # Guard will trigger the {#start}, {#stop}, {#reload}, {#run_all} and
@@ -62,5 +61,4 @@ module Guard
62
61
  _register_callbacks
63
62
  end
64
63
  end
65
-
66
64
  end
@@ -1,13 +1,13 @@
1
1
  module Guard
2
-
3
2
  class Plugin
4
-
5
3
  # Colection of shared methods between `Guard::Guard` (deprecated)
6
4
  # and `Guard::Plugin`.
7
5
  #
8
6
  module Base
9
- require 'guard/ui'
10
- require 'guard/plugin/hooker'
7
+ TEMPLATE_FORMAT = "%s/lib/guard/%s/templates/Guardfile"
8
+
9
+ require "guard/ui"
10
+ require "guard/plugin/hooker"
11
11
 
12
12
  include ::Guard::Plugin::Hooker
13
13
 
@@ -28,7 +28,7 @@ module Guard
28
28
  # @return [String]
29
29
  #
30
30
  def non_namespaced_classname
31
- self.to_s.sub('Guard::', '')
31
+ to_s.sub("Guard::", "")
32
32
  end
33
33
 
34
34
  # Returns the non-namespaced name of the plugin
@@ -50,7 +50,7 @@ module Guard
50
50
  # @param [String] plugin_location the plugin location
51
51
  #
52
52
  def template(plugin_location)
53
- File.read("#{ plugin_location }/lib/guard/#{ non_namespaced_name }/templates/Guardfile")
53
+ File.read TEMPLATE_FORMAT % [plugin_location, non_namespaced_name]
54
54
  end
55
55
  end
56
56
 
@@ -147,13 +147,17 @@ module Guard
147
147
  # String representation of the plugin.
148
148
  #
149
149
  # @example String representation of an instance of the Guard::RSpec plugin
150
+ #
150
151
  # Guard::RSpec.new.title
151
- # #=> "#<Guard::RSpec @name=rspec @group=#<Guard::Group @name=default @options={}> @watchers=[] @callbacks=[] @options={all_after_pass: true}>"
152
+ # #=> "#<Guard::RSpec @name=rspec @group=#<Guard::Group @name=default
153
+ # @options={}> @watchers=[] @callbacks=[] @options={all_after_pass:
154
+ # true}>"
152
155
  #
153
156
  # @return [String] the string representation
154
157
  #
155
158
  def to_s
156
- "#<#{self.class} @name=#{name} @group=#{group} @watchers=#{watchers} @callbacks=#{callbacks} @options=#{options}>"
159
+ "#<#{self.class} @name=#{name} @group=#{group} @watchers=#{watchers}"\
160
+ " @callbacks=#{callbacks} @options=#{options}>"
157
161
  end
158
162
 
159
163
  private
@@ -172,7 +176,6 @@ module Guard
172
176
  @callbacks = options.delete(:callbacks) { [] }
173
177
  @options = options
174
178
  end
175
-
176
179
  end
177
180
  end
178
181
  end
@@ -1,7 +1,5 @@
1
1
  module Guard
2
-
3
2
  class Plugin
4
-
5
3
  # Guard has a hook mechanism that allows you to insert callbacks for
6
4
  # individual Guard plugins.
7
5
  # By default, each of the Guard plugin instance methods has a "_begin" and
@@ -14,8 +12,7 @@ module Guard
14
12
  # wiki](https://github.com/guard/guard/wiki/Hooks-and-callbacks).
15
13
  #
16
14
  module Hooker
17
-
18
- require 'guard/ui'
15
+ require "guard/ui"
19
16
 
20
17
  # Get all callbacks registered for all Guard plugins present in the
21
18
  # Guardfile.
@@ -106,7 +103,6 @@ module Guard
106
103
  Hooker.add_callback(callback[:listener], self, callback[:events])
107
104
  end
108
105
  end
109
-
110
106
  end
111
107
  end
112
108
  end