guard 2.8.2 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
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
File without changes
File without changes
File without changes
@@ -1,221 +0,0 @@
1
- require "rbconfig"
2
- require "guard/ui"
3
-
4
- module Guard
5
- module Notifier
6
- # Base class for all notifiers.
7
- #
8
- class Base
9
- HOSTS = {
10
- darwin: "Mac OS X",
11
- linux: "Linux",
12
- freebsd: "FreeBSD",
13
- openbsd: "OpenBSD",
14
- sunos: "SunOS",
15
- solaris: "Solaris",
16
- mswin: "Windows",
17
- mingw: "Windows",
18
- cygwin: "Windows"
19
- }
20
-
21
- ERROR_ADD_GEM_AND_RUN_BUNDLE = "Please add \"gem '%s'\" to your Gemfile "\
22
- "and run Guard with \"bundle exec\"."
23
-
24
- attr_reader :options
25
-
26
- def initialize(opts = {})
27
- @options = opts
28
- end
29
-
30
- # This method should be overriden by subclasses and return an array of
31
- # OSes the notifier supports. By default, it returns :all which mean
32
- # there's no check against the current OS.
33
- #
34
- # @see HOSTS for the list of possible OSes
35
- #
36
- def self.supported_hosts
37
- :all
38
- end
39
-
40
- # Test if the notifier can be used.
41
- #
42
- # @param [Hash] opts notifier options
43
- # @option opts [Boolean] silent true if no error messages should be shown
44
- # @return [Boolean] the availability status
45
- #
46
- def self.available?(opts = {})
47
- if _supported_host?
48
- true
49
- else
50
- hosts = supported_hosts.map { |host| HOSTS[host.to_sym] }.join(", ")
51
- unless opts.fetch(:silent) { false }
52
- ::Guard::UI.error "The :#{name} notifier runs only on #{hosts}."
53
- end
54
- false
55
- end
56
- end
57
-
58
- # This method must be overriden.
59
- #
60
- def notify(_message, opts = {})
61
- options.delete(:silent)
62
- opts.replace(options.merge(opts))
63
- normalize_standard_options!(opts)
64
- end
65
-
66
- # Returns the title of the notifier.
67
- #
68
- # @example Un-modulize the class name
69
- # Guard::Notifier::FileNotifier.title
70
- # #=> 'FileNotifier'
71
- #
72
- # @return [String] the title of the notifier
73
- #
74
- def self.title
75
- to_s.sub(/.+::(\w+)$/, '\1')
76
- end
77
-
78
- # Returns the name of the notifier.
79
- #
80
- # @example Un-modulize, underscorize and downcase the class name
81
- # Guard::Notifier::FileNotifier.name
82
- # #=> 'file_notifier'
83
- #
84
- # @return [String] the name of the notifier
85
- #
86
- def self.name
87
- title.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
88
- end
89
-
90
- # Returns the name of the notifier's gem. By default it returns the
91
- # notifier name. This method can be overriden by subclasses.
92
- #
93
- # @example Un-modulize, underscorize and downcase the class name
94
- # Guard::Notifier::FileNotifier.gem_name
95
- # #=> 'file_notifier'
96
- #
97
- # @return [String] the name of the notifier's gem
98
- #
99
- def self.gem_name
100
- name
101
- end
102
-
103
- # This method tries to require the gem whose name is returned by
104
- # `.gem_name`. If a LoadError or NameError occurs, it displays an error
105
- # message (unless opts[:silent] is true) and returns false.
106
- #
107
- # @param [Hash] opts some options
108
- # @option opts [Boolean] silent true if no error messages should be shown
109
- #
110
- # @return [Boolean] whether or not the gem is loaded
111
- #
112
- def self.require_gem_safely(opts = {})
113
- require gem_name
114
- true
115
- rescue LoadError, NameError
116
- unless opts[:silent]
117
- UI.error ERROR_ADD_GEM_AND_RUN_BUNDLE % [gem_name]
118
- end
119
- false
120
- end
121
-
122
- # Returns the title of the notifier.
123
- #
124
- # @example Un-modulize the class name
125
- # Guard::Notifier::FileNotifier.new.title
126
- # #=> 'FileNotifier'
127
- #
128
- # @return [String] the title of the notifier
129
- #
130
- def title
131
- self.class.title
132
- end
133
-
134
- # Returns the name of the notifier.
135
- #
136
- # @example Un-modulize, underscorize and downcase the class name
137
- # Guard::Notifier::FileNotifier.new.name
138
- # #=> 'file_notifier'
139
- #
140
- # @return [String] the name of the notifier
141
- #
142
- def name
143
- self.class.name
144
- end
145
-
146
- # Paths where all Guard images are located
147
- #
148
- # @return [Pathname] the path to the images directory
149
- #
150
- def images_path
151
- @images_path ||= Pathname.new(__FILE__).dirname + "../../../images"
152
- end
153
-
154
- # @private
155
- #
156
- # Checks if the current OS is supported by the notifier.
157
- #
158
- # @see .supported_hosts
159
- #
160
- def self._supported_host?
161
- supported_hosts == :all ||
162
- RbConfig::CONFIG["host_os"] =~ /#{supported_hosts.join('|')}/
163
- end
164
-
165
- # Set or modify the `:title`, `:type` and `:image` options for a
166
- # notification. Should be used in `#notify`.
167
- #
168
- # @param [Hash] opts additional notification library options
169
- # @option opts [String] type the notification type. Either 'success',
170
- # 'pending', 'failed' or 'notify'
171
- # @option opts [String] title the notification title
172
- # @option opts [String] image the path to the notification image
173
- #
174
- def normalize_standard_options!(opts)
175
- opts[:title] ||= "Guard"
176
- opts[:type] ||= _notification_type(opts.fetch(:image, :success))
177
- opts[:image] = _image_path(opts.delete(:image) { :success })
178
- end
179
-
180
- private
181
-
182
- # Get the image path for an image symbol for the following
183
- # known image types:
184
- #
185
- # - failed
186
- # - pending
187
- # - success
188
- #
189
- # If the image is not a known symbol, it will be returned unmodified.
190
- #
191
- # @param [Symbol, String] image the image symbol or path to an image
192
- #
193
- # @return [String] the image path
194
- #
195
- def _image_path(image)
196
- case image
197
- when :failed, :pending, :success
198
- images_path.join("#{image}.png").to_s
199
- else
200
- image
201
- end
202
- end
203
-
204
- # Get the notification type depending on the
205
- # image that has been selected for the notification.
206
- #
207
- # @param [Symbol, String] image the image symbol or path to an image
208
- #
209
- # @return [String] the notification type
210
- #
211
- def _notification_type(image)
212
- case image
213
- when :failed, :pending, :success
214
- image
215
- else
216
- :notify
217
- end
218
- end
219
- end
220
- end
221
- end
@@ -1,339 +0,0 @@
1
- require "guard/notifiers/base"
2
-
3
- module Guard
4
- module Notifier
5
- # Changes the color of the Tmux status bar and optionally
6
- # shows messages in the status bar.
7
- #
8
- # @example Add the `:tmux` notifier to your `Guardfile`
9
- # notification :tmux
10
- #
11
- # @example Enable text messages
12
- # notification :tmux, display_message: true
13
- #
14
- # @example Customize the tmux status colored for notifications
15
- # notification :tmux, color_location: 'status-right-bg'
16
- #
17
- class Tmux < Base
18
- # Default options for the tmux notifications.
19
- DEFAULTS = {
20
- client: "tmux",
21
- tmux_environment: "TMUX",
22
- success: "green",
23
- failed: "red",
24
- pending: "yellow",
25
- default: "green",
26
- timeout: 5,
27
- display_message: false,
28
- default_message_format: "%s - %s",
29
- default_message_color: "white",
30
- display_on_all_clients: false,
31
- display_title: false,
32
- default_title_format: "%s - %s",
33
- line_separator: " - ",
34
- change_color: true,
35
- color_location: "status-left-bg"
36
- }
37
-
38
- ERROR_NOT_INSIDE_SESSION = "The :tmux notifier runs only on when Guard"\
39
- " is executed inside of a tmux session."
40
-
41
- def self.available?(opts = {})
42
- super && _register!(opts)
43
- end
44
-
45
- # @private
46
- #
47
- # @return [Boolean] whether or not a TMUX environment is available
48
- #
49
- def self._tmux_environment_available?(opts)
50
- !ENV[opts.fetch(:tmux_environment, DEFAULTS[:tmux_environment])].nil?
51
- end
52
-
53
- # @private
54
- #
55
- # Detects if a TMUX environment is available and if not,
56
- # displays an error message unless `opts[:silent]` is true.
57
- #
58
- # @return [Boolean] whether or not a TMUX environment is available
59
- #
60
- def self._register!(opts)
61
- @options_stored = false
62
- if _tmux_environment_available?(opts)
63
- true
64
- else
65
- unless opts[:silent]
66
- ::Guard::UI.error ERROR_NOT_INSIDE_SESSION
67
- end
68
- false
69
- end
70
- end
71
-
72
- # Shows a system notification.
73
- #
74
- # By default, the Tmux notifier only makes
75
- # use of a color based notification, changing the background color of the
76
- # `color_location` to the color defined in either the `success`,
77
- # `failed`, `pending` or `default`, depending on the notification type.
78
- #
79
- # You may enable an extra explicit message by setting `display_message`
80
- # to true, and may further disable the colorization by setting
81
- # `change_color` to false.
82
- #
83
- # @param [String] title the notification title
84
- # @param [Hash] opts additional notification library options
85
- # @option opts [String] type the notification type. Either 'success',
86
- # 'pending', 'failed' or 'notify'
87
- # @option opts [String] message the notification message body
88
- # @option opts [String] image the path to the notification image
89
- # @option opts [Boolean] change_color whether to show a color
90
- # notification
91
- # @option opts [String,Array] color_location the location where to draw
92
- # the color notification
93
- # @option opts [Boolean] display_message whether to display a message
94
- # or not
95
- # @option opts [Boolean] display_on_all_clients whether to display a
96
- # message on all tmux clients or not
97
- #
98
- def notify(message, opts = {})
99
- super
100
- opts.delete(:image)
101
-
102
- if opts.fetch(:change_color, DEFAULTS[:change_color])
103
- options = opts.fetch(:color_location, DEFAULTS[:color_location])
104
- color_locations = Array(options)
105
- color = tmux_color(opts[:type], opts)
106
-
107
- color_locations.each do |color_location|
108
- _run_client "set", "#{self.class._quiet_option}"\
109
- "#{color_location} #{color}"
110
- end
111
- end
112
-
113
- type = opts.delete(:type).to_s
114
- title = opts.delete(:title)
115
-
116
- if opts.fetch(:display_title, DEFAULTS[:display_title])
117
- display_title(type, title, message, opts)
118
- end
119
-
120
- return unless opts.fetch(:display_message, DEFAULTS[:display_message])
121
- display_message(type, title, message, opts)
122
- end
123
-
124
- # Displays a message in the title bar of the terminal.
125
- #
126
- # @param [String] title the notification title
127
- # @param [String] message the notification message body
128
- # @param [Hash] options additional notification library options
129
- # @option options [String] success_message_format a string to use as
130
- # formatter for the success message.
131
- # @option options [String] failed_message_format a string to use as
132
- # formatter for the failed message.
133
- # @option options [String] pending_message_format a string to use as
134
- # formatter for the pending message.
135
- # @option options [String] default_message_format a string to use as
136
- # formatter when no format per type is defined.
137
- #
138
- def display_title(type, title, message, opts = {})
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)
143
- teaser_message = message.split("\n").first
144
- display_title = title_format % [title, teaser_message]
145
-
146
- _run_client "set-option", "#{self.class._quiet_option}"\
147
- "set-titles-string '#{display_title}'"
148
- end
149
-
150
- # Displays a message in the status bar of tmux.
151
- #
152
- # @param [String] type the notification type. Either 'success',
153
- # 'pending', 'failed' or 'notify'
154
- # @param [String] title the notification title
155
- # @param [String] message the notification message body
156
- # @param [Hash] options additional notification library options
157
- # @option options [Integer] timeout the amount of seconds to show the
158
- # message in the status bar
159
- # @option options [String] success_message_format a string to use as
160
- # formatter for the success message.
161
- # @option options [String] failed_message_format a string to use as
162
- # formatter for the failed message.
163
- # @option options [String] pending_message_format a string to use as
164
- # formatter for the pending message.
165
- # @option options [String] default_message_format a string to use as
166
- # formatter when no format per type is defined.
167
- # @option options [String] success_message_color the success notification
168
- # foreground color name.
169
- # @option options [String] failed_message_color the failed notification
170
- # foreground color name.
171
- # @option options [String] pending_message_color the pending notification
172
- # foreground color name.
173
- # @option options [String] default_message_color a notification
174
- # foreground color to use when no color per type is defined.
175
- # @option options [String] line_separator a string to use instead of a
176
- # line-break.
177
- #
178
- def display_message(type, title, message, opts = {})
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
-
189
- display_time = opts.fetch(:timeout, DEFAULTS[:timeout])
190
- separator = opts.fetch(:line_separator, DEFAULTS[:line_separator])
191
-
192
- color = tmux_color type, opts
193
- formatted_message = message.split("\n").join(separator)
194
- display_message = message_format % [title, formatted_message]
195
-
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}'"
205
- end
206
-
207
- # Get the Tmux color for the notification type.
208
- # You can configure your own color by overwriting the defaults.
209
- #
210
- # @param [String] type the notification type
211
- # @return [String] the name of the emacs color
212
- #
213
- def tmux_color(type, opts = {})
214
- type = type.to_sym
215
-
216
- opts[type] || DEFAULTS[type] || opts[:default] || DEFAULTS[:default]
217
- end
218
-
219
- # Notification starting, save the current Tmux settings
220
- # and quiet the Tmux output.
221
- #
222
- def self.turn_on
223
- unless @options_stored
224
- _reset_options_store
225
-
226
- _clients.each do |client|
227
- @options_store[client].merge!(_options_for_client(client))
228
- end
229
-
230
- @options_stored = true
231
- end
232
- end
233
-
234
- # Notification stopping. Restore the previous Tmux state
235
- # if available (existing options are restored, new options
236
- # are unset) and unquiet the Tmux output.
237
- #
238
- def self.turn_off
239
- if @options_stored
240
- @options_store.each do |client, options|
241
- options.each do |key, value|
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(" "))
250
- end
251
- end
252
- _reset_options_store
253
- end
254
- end
255
-
256
- def self.options_store
257
- @options_store ||= {}
258
- end
259
-
260
- private
261
-
262
- def self._clients
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
-
270
- ttys
271
- end
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
-
286
- def _clients
287
- self.class._clients
288
- end
289
-
290
- def _run_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}")
301
- end
302
- end
303
-
304
- def _client_cmd_flag(cmd)
305
- case cmd
306
- when "set", "set-option" then "-t"
307
- when "display-message" then "-c"
308
- end
309
- end
310
-
311
- # Reset the internal Tmux options store defaults.
312
- #
313
- def self._reset_options_store
314
- @options_stored = false
315
- @options_store = {}
316
-
317
- _clients.each do |client|
318
- @options_store[client] = {
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
326
- }
327
- end
328
- end
329
-
330
- def self._tmux_version
331
- @@tmux_version ||= Float(Sheller.stdout("tmux -V")[/\d+\.\d+/])
332
- end
333
-
334
- def self._quiet_option
335
- "-q " if _tmux_version >= 1.7
336
- end
337
- end
338
- end
339
- end