guard 0.8.4 → 0.8.5
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.
- data/CHANGELOG.md +348 -330
- data/LICENSE +19 -19
- data/README.md +464 -431
- data/bin/guard +6 -6
- data/lib/guard.rb +452 -414
- data/lib/guard/cli.rb +119 -178
- data/lib/guard/dsl.rb +370 -370
- data/lib/guard/dsl_describer.rb +150 -60
- data/lib/guard/group.rb +37 -37
- data/lib/guard/guard.rb +129 -113
- data/lib/guard/hook.rb +118 -118
- data/lib/guard/interactor.rb +110 -44
- data/lib/guard/listener.rb +350 -350
- data/lib/guard/listeners/darwin.rb +66 -66
- data/lib/guard/listeners/linux.rb +97 -97
- data/lib/guard/listeners/polling.rb +55 -55
- data/lib/guard/listeners/windows.rb +61 -61
- data/lib/guard/notifier.rb +290 -211
- data/lib/guard/templates/Guardfile +2 -2
- data/lib/guard/ui.rb +193 -188
- data/lib/guard/version.rb +6 -6
- data/lib/guard/watcher.rb +114 -110
- data/man/guard.1 +93 -93
- data/man/guard.1.html +176 -176
- metadata +107 -59
data/lib/guard/notifier.rb
CHANGED
@@ -1,211 +1,290 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
require 'pathname'
|
3
|
-
require 'guard/ui'
|
4
|
-
|
5
|
-
module Guard
|
6
|
-
|
7
|
-
# The notifier class handles cross-platform system notifications that supports:
|
8
|
-
#
|
9
|
-
# - Growl on Mac OS X
|
10
|
-
# - Libnotify on Linux
|
11
|
-
# - Notifu on Windows
|
12
|
-
#
|
13
|
-
module Notifier
|
14
|
-
|
15
|
-
# Application name as shown in the specific notification settings
|
16
|
-
APPLICATION_NAME = "Guard"
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
1
|
+
require 'rbconfig'
|
2
|
+
require 'pathname'
|
3
|
+
require 'guard/ui'
|
4
|
+
|
5
|
+
module Guard
|
6
|
+
|
7
|
+
# The notifier class handles cross-platform system notifications that supports:
|
8
|
+
#
|
9
|
+
# - Growl on Mac OS X
|
10
|
+
# - Libnotify on Linux
|
11
|
+
# - Notifu on Windows
|
12
|
+
#
|
13
|
+
module Notifier
|
14
|
+
|
15
|
+
# Application name as shown in the specific notification settings
|
16
|
+
APPLICATION_NAME = "Guard"
|
17
|
+
|
18
|
+
class << self
|
19
|
+
|
20
|
+
attr_accessor :growl_library, :gntp
|
21
|
+
|
22
|
+
# Turn notifications off.
|
23
|
+
#
|
24
|
+
def turn_off
|
25
|
+
ENV["GUARD_NOTIFY"] = 'false'
|
26
|
+
end
|
27
|
+
|
28
|
+
# Turn notifications on. This tries to load the platform
|
29
|
+
# specific notification library.
|
30
|
+
#
|
31
|
+
# @return [Boolean] whether the notification could be enabled.
|
32
|
+
#
|
33
|
+
def turn_on
|
34
|
+
ENV["GUARD_NOTIFY"] = 'true'
|
35
|
+
case RbConfig::CONFIG['target_os']
|
36
|
+
when /darwin/i
|
37
|
+
require_growl
|
38
|
+
when /linux/i
|
39
|
+
require_libnotify
|
40
|
+
when /mswin|mingw/i
|
41
|
+
require_rbnotifu
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Show a message with the system notification.
|
46
|
+
#
|
47
|
+
# @see .image_path
|
48
|
+
#
|
49
|
+
# @param [String] the message to show
|
50
|
+
# @option options [Symbol, String] image the image symbol or path to an image
|
51
|
+
# @option options [String] title the notification title
|
52
|
+
#
|
53
|
+
def notify(message, options = { })
|
54
|
+
if enabled?
|
55
|
+
image = options.delete(:image) || :success
|
56
|
+
title = options.delete(:title) || "Guard"
|
57
|
+
|
58
|
+
case RbConfig::CONFIG['target_os']
|
59
|
+
when /darwin/i
|
60
|
+
notify_mac(title, message, image, options)
|
61
|
+
when /linux/i
|
62
|
+
notify_linux(title, message, image, options)
|
63
|
+
when /mswin|mingw/i
|
64
|
+
notify_windows(title, message, image, options)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Test if the notifications are enabled and available.
|
70
|
+
#
|
71
|
+
# @return [Boolean] whether the notifications are available
|
72
|
+
#
|
73
|
+
def enabled?
|
74
|
+
ENV["GUARD_NOTIFY"] == 'true'
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
# Send a message to Growl either with the `growl` gem or the `growl_notify` gem.
|
80
|
+
#
|
81
|
+
# @param [String] title the notification title
|
82
|
+
# @param [String] message the message to show
|
83
|
+
# @param [Symbol, String] the image to user
|
84
|
+
# @param [Hash] options the growl options
|
85
|
+
#
|
86
|
+
def notify_mac(title, message, image, options = { })
|
87
|
+
require_growl # need for guard-rspec formatter that is called out of guard scope
|
88
|
+
|
89
|
+
notification = { :title => title, :icon => image_path(image) }.merge(options)
|
90
|
+
|
91
|
+
case self.growl_library
|
92
|
+
when :growl_notify
|
93
|
+
notification.delete(:name)
|
94
|
+
|
95
|
+
GrowlNotify.send_notification({
|
96
|
+
:description => message,
|
97
|
+
:application_name => APPLICATION_NAME
|
98
|
+
}.merge(notification))
|
99
|
+
|
100
|
+
when :ruby_gntp
|
101
|
+
icon = "file://#{ notification.delete(:icon) }"
|
102
|
+
|
103
|
+
self.gntp.notify({
|
104
|
+
:name => [:pending, :success, :failed].include?(image) ? image.to_s : 'notify',
|
105
|
+
:text => message,
|
106
|
+
:icon => icon
|
107
|
+
}.merge(notification))
|
108
|
+
|
109
|
+
when :growl
|
110
|
+
Growl.notify(message, {
|
111
|
+
:name => APPLICATION_NAME
|
112
|
+
}.merge(notification))
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Send a message to libnotify.
|
117
|
+
#
|
118
|
+
# @param [String] title the notification title
|
119
|
+
# @param [String] message the message to show
|
120
|
+
# @param [Symbol, String] the image to user
|
121
|
+
# @param [Hash] options the libnotify options
|
122
|
+
#
|
123
|
+
def notify_linux(title, message, image, options = { })
|
124
|
+
require_libnotify # need for guard-rspec formatter that is called out of guard scope
|
125
|
+
|
126
|
+
notification = { :body => message, :summary => title, :icon_path => image_path(image), :transient => true }
|
127
|
+
Libnotify.show notification.merge(options)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Send a message to notifu.
|
131
|
+
#
|
132
|
+
# @param [String] title the notification title
|
133
|
+
# @param [String] message the message to show
|
134
|
+
# @param [Symbol, String] the image to user
|
135
|
+
# @param [Hash] options the notifu options
|
136
|
+
#
|
137
|
+
def notify_windows(title, message, image, options = { })
|
138
|
+
require_rbnotifu # need for guard-rspec formatter that is called out of guard scope
|
139
|
+
|
140
|
+
notification = { :message => message, :title => title, :type => image_level(image), :time => 3 }
|
141
|
+
Notifu.show notification.merge(options)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Get the image path for an image symbol.
|
145
|
+
#
|
146
|
+
# Known symbols are:
|
147
|
+
#
|
148
|
+
# - failed
|
149
|
+
# - pending
|
150
|
+
# - success
|
151
|
+
#
|
152
|
+
# @param [Symbol] image the image name
|
153
|
+
# @return [String] the image path
|
154
|
+
#
|
155
|
+
def image_path(image)
|
156
|
+
images_path = Pathname.new(File.dirname(__FILE__)).join('../../images')
|
157
|
+
case image
|
158
|
+
when :failed
|
159
|
+
images_path.join("failed.png").to_s
|
160
|
+
when :pending
|
161
|
+
images_path.join("pending.png").to_s
|
162
|
+
when :success
|
163
|
+
images_path.join("success.png").to_s
|
164
|
+
else
|
165
|
+
# path given
|
166
|
+
image
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# The notification level type for the given image.
|
171
|
+
#
|
172
|
+
# @param [Symbol] image the image
|
173
|
+
# @return [Symbol] the level
|
174
|
+
#
|
175
|
+
def image_level(image)
|
176
|
+
case image
|
177
|
+
when :failed
|
178
|
+
:error
|
179
|
+
when :pending
|
180
|
+
:warn
|
181
|
+
when :success
|
182
|
+
:info
|
183
|
+
else
|
184
|
+
:info
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
# Try to safely load growl and turns notifications off on load failure.
|
189
|
+
# The Guard notifier knows three different library to handle sending
|
190
|
+
# Growl messages and tries to loading them in the given order:
|
191
|
+
#
|
192
|
+
# - [Growl Notify](https://github.com/scottdavis/growl_notify)
|
193
|
+
# - [Ruby GNTP](https://github.com/snaka/ruby_gntp)
|
194
|
+
# - [Growl](https://github.com/visionmedia/growl)
|
195
|
+
#
|
196
|
+
# On successful loading of any of the libraries, the active library name is
|
197
|
+
# accessible through `.growl_library`.
|
198
|
+
#
|
199
|
+
def require_growl
|
200
|
+
self.growl_library = try_growl_notify || try_ruby_gntp || try_growl
|
201
|
+
|
202
|
+
unless self.growl_library
|
203
|
+
turn_off
|
204
|
+
UI.info "Please install growl_notify or growl gem for Mac OS X notification support and add it to your Gemfile"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# Try to load the `growl_notify` gem.
|
209
|
+
#
|
210
|
+
# @return [Symbol, nil] A symbol with the name of the loaded library
|
211
|
+
#
|
212
|
+
def try_growl_notify
|
213
|
+
require 'growl_notify'
|
214
|
+
|
215
|
+
begin
|
216
|
+
if GrowlNotify.application_name != APPLICATION_NAME
|
217
|
+
GrowlNotify.config do |c|
|
218
|
+
c.notifications = c.default_notifications = [APPLICATION_NAME]
|
219
|
+
c.application_name = c.notifications.first
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
rescue ::GrowlNotify::GrowlNotFound
|
224
|
+
turn_off
|
225
|
+
UI.info "Please install Growl from http://growl.info"
|
226
|
+
end
|
227
|
+
|
228
|
+
:growl_notify
|
229
|
+
|
230
|
+
rescue LoadError
|
231
|
+
end
|
232
|
+
|
233
|
+
# Try to load the `ruby_gntp` gem and register the available
|
234
|
+
# notification channels.
|
235
|
+
#
|
236
|
+
# @return [Symbol, nil] A symbol with the name of the loaded library
|
237
|
+
#
|
238
|
+
def try_ruby_gntp
|
239
|
+
require 'ruby_gntp'
|
240
|
+
|
241
|
+
self.gntp = GNTP.new(APPLICATION_NAME)
|
242
|
+
self.gntp.register(:notifications => [
|
243
|
+
{ :name => 'notify', :enabled => true },
|
244
|
+
{ :name => 'failed', :enabled => true },
|
245
|
+
{ :name => 'pending', :enabled => true },
|
246
|
+
{ :name => 'success', :enabled => true }
|
247
|
+
])
|
248
|
+
|
249
|
+
:ruby_gntp
|
250
|
+
|
251
|
+
rescue LoadError
|
252
|
+
end
|
253
|
+
|
254
|
+
# Try to load the `growl_notify` gem.
|
255
|
+
#
|
256
|
+
# @return [Symbol, nil] A symbol with the name of the loaded library
|
257
|
+
#
|
258
|
+
def try_growl
|
259
|
+
require 'growl'
|
260
|
+
|
261
|
+
:growl
|
262
|
+
|
263
|
+
rescue LoadError
|
264
|
+
end
|
265
|
+
|
266
|
+
# Try to safely load libnotify and turns notifications
|
267
|
+
# off on load failure.
|
268
|
+
#
|
269
|
+
def require_libnotify
|
270
|
+
require 'libnotify'
|
271
|
+
|
272
|
+
rescue LoadError
|
273
|
+
turn_off
|
274
|
+
UI.info "Please install libnotify gem for Linux notification support and add it to your Gemfile"
|
275
|
+
end
|
276
|
+
|
277
|
+
# Try to safely load rb-notifu and turns notifications
|
278
|
+
# off on load failure.
|
279
|
+
#
|
280
|
+
def require_rbnotifu
|
281
|
+
require 'rb-notifu'
|
282
|
+
|
283
|
+
rescue LoadError
|
284
|
+
turn_off
|
285
|
+
UI.info "Please install rb-notifu gem for Windows notification support and add it to your Gemfile"
|
286
|
+
end
|
287
|
+
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|