guard 2.6.1 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +73 -58
- data/bin/guard +2 -2
- data/lib/guard.rb +64 -59
- data/lib/guard/cli.rb +66 -60
- data/lib/guard/cli.rb.orig +215 -0
- data/lib/guard/commander.rb +45 -69
- data/lib/guard/commands/all.rb +21 -19
- data/lib/guard/commands/change.rb +17 -22
- data/lib/guard/commands/notification.rb +15 -16
- data/lib/guard/commands/pause.rb +14 -15
- data/lib/guard/commands/reload.rb +19 -20
- data/lib/guard/commands/scope.rb +23 -19
- data/lib/guard/commands/show.rb +13 -16
- data/lib/guard/deprecated_methods.rb +6 -10
- data/lib/guard/deprecator.rb +52 -37
- data/lib/guard/dsl.rb +55 -33
- data/lib/guard/dsl_describer.rb +83 -31
- data/lib/guard/dsl_describer.rb.orig +184 -0
- data/lib/guard/group.rb +7 -6
- data/lib/guard/guard.rb +4 -4
- data/lib/guard/guard.rb.orig +42 -0
- data/lib/guard/guardfile.rb +12 -13
- data/lib/guard/guardfile/evaluator.rb +77 -55
- data/lib/guard/guardfile/evaluator.rb.orig +275 -0
- data/lib/guard/guardfile/generator.rb +25 -20
- data/lib/guard/interactor.rb +52 -293
- data/lib/guard/interactor.rb.orig +85 -0
- data/lib/guard/jobs/base.rb +21 -0
- data/lib/guard/jobs/pry_wrapper.rb +290 -0
- data/lib/guard/jobs/pry_wrapper.rb.orig +293 -0
- data/lib/guard/jobs/sleep.rb +25 -0
- data/lib/guard/notifier.rb +42 -39
- data/lib/guard/notifiers/base.rb +25 -24
- data/lib/guard/notifiers/emacs.rb +30 -24
- data/lib/guard/notifiers/file_notifier.rb +3 -7
- data/lib/guard/notifiers/gntp.rb +22 -22
- data/lib/guard/notifiers/growl.rb +16 -15
- data/lib/guard/notifiers/libnotify.rb +7 -10
- data/lib/guard/notifiers/notifysend.rb +15 -14
- data/lib/guard/notifiers/rb_notifu.rb +8 -10
- data/lib/guard/notifiers/terminal_notifier.rb +15 -11
- data/lib/guard/notifiers/terminal_title.rb +4 -8
- data/lib/guard/notifiers/tmux.rb +104 -71
- data/lib/guard/options.rb +1 -5
- data/lib/guard/plugin.rb +1 -3
- data/lib/guard/plugin/base.rb +12 -9
- data/lib/guard/plugin/hooker.rb +1 -5
- data/lib/guard/plugin_util.rb +46 -25
- data/lib/guard/plugin_util.rb.orig +178 -0
- data/lib/guard/rake_task.rb +4 -7
- data/lib/guard/reevaluator.rb +13 -0
- data/lib/guard/runner.rb +50 -78
- data/lib/guard/runner.rb.orig +200 -0
- data/lib/guard/setuper.rb +199 -130
- data/lib/guard/setuper.rb.orig +348 -0
- data/lib/guard/sheller.rb +107 -0
- data/lib/guard/tags +367 -0
- data/lib/guard/ui.rb +50 -38
- data/lib/guard/ui.rb.orig +254 -0
- data/lib/guard/ui/colors.rb +17 -21
- data/lib/guard/version.rb +1 -1
- data/lib/guard/version.rb.orig +3 -0
- data/lib/guard/watcher.rb +49 -62
- metadata +21 -4
- data/lib/guard/notifiers/growl_notify.rb +0 -93
@@ -0,0 +1,25 @@
|
|
1
|
+
require "guard/jobs/base"
|
2
|
+
|
3
|
+
module Guard
|
4
|
+
module Jobs
|
5
|
+
class Sleep < Base
|
6
|
+
def foreground
|
7
|
+
::Guard::UI.debug "Guards jobs done. Sleeping..."
|
8
|
+
sleep
|
9
|
+
::Guard::UI.debug "Sleep interrupted by events."
|
10
|
+
:stopped
|
11
|
+
rescue Interrupt
|
12
|
+
::Guard::UI.debug "Sleep interrupted by user."
|
13
|
+
:exit
|
14
|
+
end
|
15
|
+
|
16
|
+
def background
|
17
|
+
Thread.main.wakeup
|
18
|
+
end
|
19
|
+
|
20
|
+
def handle_interrupt
|
21
|
+
Thread.main.raise Interrupt
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/guard/notifier.rb
CHANGED
@@ -1,29 +1,26 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require 'guard/notifiers/tmux'
|
1
|
+
require "yaml"
|
2
|
+
require "rbconfig"
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
require "guard/ui"
|
6
|
+
require "guard/notifiers/emacs"
|
7
|
+
require "guard/notifiers/file_notifier"
|
8
|
+
require "guard/notifiers/gntp"
|
9
|
+
require "guard/notifiers/growl"
|
10
|
+
require "guard/notifiers/libnotify"
|
11
|
+
require "guard/notifiers/notifysend"
|
12
|
+
require "guard/notifiers/rb_notifu"
|
13
|
+
require "guard/notifiers/terminal_notifier"
|
14
|
+
require "guard/notifiers/terminal_title"
|
15
|
+
require "guard/notifiers/tmux"
|
17
16
|
|
18
17
|
module Guard
|
19
|
-
|
20
18
|
# The notifier handles sending messages to different notifiers. Currently the
|
21
19
|
# following
|
22
20
|
# libraries are supported:
|
23
21
|
#
|
24
22
|
# * Ruby GNTP
|
25
23
|
# * Growl
|
26
|
-
# * GrowlNotify
|
27
24
|
# * Libnotify
|
28
25
|
# * rb-notifu
|
29
26
|
# * emacs
|
@@ -45,7 +42,7 @@ module Guard
|
|
45
42
|
# The notification type selection is based on the image option that is
|
46
43
|
# sent to {#notify}. Each image type has its own notification type, and
|
47
44
|
# notifications with custom images goes all sent as type `notify`. The
|
48
|
-
# `gntp`
|
45
|
+
# `gntp` notifier is able to register these types
|
49
46
|
# at Growl and allows customization of each notification type.
|
50
47
|
#
|
51
48
|
# Guard can be configured to make use of more than one notifier at once.
|
@@ -53,7 +50,6 @@ module Guard
|
|
53
50
|
# @see Guard::Dsl
|
54
51
|
#
|
55
52
|
module Notifier
|
56
|
-
|
57
53
|
extend self
|
58
54
|
|
59
55
|
# List of available notifiers, grouped by functionality
|
@@ -61,7 +57,6 @@ module Guard
|
|
61
57
|
{
|
62
58
|
gntp: GNTP,
|
63
59
|
growl: Growl,
|
64
|
-
growl_notify: GrowlNotify,
|
65
60
|
terminal_notifier: TerminalNotifier,
|
66
61
|
libnotify: Libnotify,
|
67
62
|
notifysend: NotifySend,
|
@@ -74,17 +69,17 @@ module Guard
|
|
74
69
|
]
|
75
70
|
|
76
71
|
def notifiers
|
77
|
-
ENV[
|
72
|
+
ENV["GUARD_NOTIFIERS"] ? YAML::load(ENV["GUARD_NOTIFIERS"]) : []
|
78
73
|
end
|
79
74
|
|
80
75
|
def notifiers=(notifiers)
|
81
|
-
ENV[
|
76
|
+
ENV["GUARD_NOTIFIERS"] = YAML::dump(notifiers)
|
82
77
|
end
|
83
78
|
|
84
79
|
# Clear available notifications.
|
85
80
|
#
|
86
81
|
def clear_notifiers
|
87
|
-
ENV[
|
82
|
+
ENV["GUARD_NOTIFIERS"] = nil
|
88
83
|
end
|
89
84
|
|
90
85
|
# Turn notifications on. If no notifications are defined in the `Guardfile`
|
@@ -94,19 +89,24 @@ module Guard
|
|
94
89
|
# @option options [Boolean] silent disable any logging
|
95
90
|
#
|
96
91
|
def turn_on(opts = {})
|
97
|
-
|
92
|
+
if notifiers.empty? && (::Guard.options || {})[:notify]
|
93
|
+
_auto_detect_notification
|
94
|
+
end
|
98
95
|
|
99
96
|
if notifiers.empty?
|
100
97
|
turn_off
|
101
98
|
else
|
102
99
|
notifiers.each do |notifier|
|
103
100
|
notifier_class = _get_notifier_module(notifier[:name])
|
104
|
-
|
101
|
+
unless opts[:silent]
|
102
|
+
::Guard::UI.info \
|
103
|
+
"Guard is using #{ notifier_class.title } to send notifications."
|
104
|
+
end
|
105
105
|
|
106
106
|
notifier_class.turn_on if notifier_class.respond_to?(:turn_on)
|
107
107
|
end
|
108
108
|
|
109
|
-
ENV[
|
109
|
+
ENV["GUARD_NOTIFY"] = "true"
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
@@ -119,14 +119,14 @@ module Guard
|
|
119
119
|
notifier_class.turn_off if notifier_class.respond_to?(:turn_off)
|
120
120
|
end
|
121
121
|
|
122
|
-
ENV[
|
122
|
+
ENV["GUARD_NOTIFY"] = "false"
|
123
123
|
end
|
124
124
|
|
125
125
|
# Toggle the system notifications on/off
|
126
126
|
#
|
127
127
|
def toggle
|
128
128
|
if enabled?
|
129
|
-
::Guard::UI.info
|
129
|
+
::Guard::UI.info "Turn off notifications"
|
130
130
|
turn_off
|
131
131
|
else
|
132
132
|
turn_on
|
@@ -138,7 +138,7 @@ module Guard
|
|
138
138
|
# @return [Boolean] whether the notifications are on
|
139
139
|
#
|
140
140
|
def enabled?
|
141
|
-
ENV[
|
141
|
+
ENV["GUARD_NOTIFY"] == "true"
|
142
142
|
end
|
143
143
|
|
144
144
|
# Add a notification library to be used.
|
@@ -175,8 +175,10 @@ module Guard
|
|
175
175
|
|
176
176
|
begin
|
177
177
|
notifier.notify(message, opts.dup)
|
178
|
-
rescue
|
179
|
-
::Guard::UI.error
|
178
|
+
rescue RuntimeError => e
|
179
|
+
::Guard::UI.error \
|
180
|
+
"Error sending notification with #{ notifier.name }: #{ e.message }"
|
181
|
+
|
180
182
|
::Guard::UI.debug e.backtrace.join("\n")
|
181
183
|
end
|
182
184
|
end
|
@@ -191,11 +193,9 @@ module Guard
|
|
191
193
|
#
|
192
194
|
def _get_notifier_module(name)
|
193
195
|
NOTIFIERS.each do |group|
|
194
|
-
|
195
|
-
|
196
|
-
end
|
196
|
+
next unless (notifier = group.detect { |n, _| n == name })
|
197
|
+
return notifier.last
|
197
198
|
end
|
198
|
-
|
199
199
|
nil
|
200
200
|
end
|
201
201
|
|
@@ -208,12 +208,15 @@ module Guard
|
|
208
208
|
available = nil
|
209
209
|
|
210
210
|
NOTIFIERS.each do |group|
|
211
|
-
notifier_added = group.
|
211
|
+
notifier_added = group.detect do |name, _|
|
212
|
+
add_notifier(name, silent: true)
|
213
|
+
end
|
212
214
|
available ||= notifier_added
|
213
215
|
end
|
214
216
|
|
215
|
-
|
217
|
+
return if available
|
218
|
+
::Guard::UI.info \
|
219
|
+
"Guard could not detect any of the supported notification libraries."
|
216
220
|
end
|
217
221
|
end
|
218
|
-
|
219
222
|
end
|
data/lib/guard/notifiers/base.rb
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rbconfig"
|
2
|
+
require "guard/ui"
|
3
3
|
|
4
4
|
module Guard
|
5
5
|
module Notifier
|
6
|
-
|
7
6
|
# Base class for all notifiers.
|
8
7
|
#
|
9
8
|
class Base
|
10
|
-
|
11
9
|
HOSTS = {
|
12
|
-
darwin:
|
13
|
-
linux:
|
14
|
-
freebsd:
|
15
|
-
openbsd:
|
16
|
-
sunos:
|
17
|
-
solaris:
|
18
|
-
mswin:
|
19
|
-
mingw:
|
20
|
-
cygwin:
|
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"
|
21
19
|
}
|
22
20
|
|
21
|
+
ERROR_ADD_GEM_AND_RUN_BUNDLE = "Please add \"gem '%s'\" to your Gemfile "\
|
22
|
+
"and run Guard with \"bundle exec\"."
|
23
|
+
|
23
24
|
attr_reader :options
|
24
25
|
|
25
26
|
def initialize(opts = {})
|
@@ -46,15 +47,17 @@ module Guard
|
|
46
47
|
if _supported_host?
|
47
48
|
true
|
48
49
|
else
|
49
|
-
hosts = supported_hosts.map { |host| HOSTS[host.to_sym] }.join(
|
50
|
-
|
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
|
51
54
|
false
|
52
55
|
end
|
53
56
|
end
|
54
57
|
|
55
58
|
# This method must be overriden.
|
56
59
|
#
|
57
|
-
def notify(
|
60
|
+
def notify(_message, opts = {})
|
58
61
|
options.delete(:silent)
|
59
62
|
opts.replace(options.merge(opts))
|
60
63
|
normalize_standard_options!(opts)
|
@@ -69,7 +72,7 @@ module Guard
|
|
69
72
|
# @return [String] the title of the notifier
|
70
73
|
#
|
71
74
|
def self.title
|
72
|
-
|
75
|
+
to_s.sub(/.+::(\w+)$/, '\1')
|
73
76
|
end
|
74
77
|
|
75
78
|
# Returns the name of the notifier.
|
@@ -111,7 +114,7 @@ module Guard
|
|
111
114
|
true
|
112
115
|
rescue LoadError, NameError
|
113
116
|
unless opts[:silent]
|
114
|
-
|
117
|
+
UI.error ERROR_ADD_GEM_AND_RUN_BUNDLE % [gem_name]
|
115
118
|
end
|
116
119
|
false
|
117
120
|
end
|
@@ -145,7 +148,7 @@ module Guard
|
|
145
148
|
# @return [Pathname] the path to the images directory
|
146
149
|
#
|
147
150
|
def images_path
|
148
|
-
@images_path ||= Pathname.new(
|
151
|
+
@images_path ||= Pathname.new(__FILE__).dirname + "../../../images"
|
149
152
|
end
|
150
153
|
|
151
154
|
# @private
|
@@ -156,7 +159,7 @@ module Guard
|
|
156
159
|
#
|
157
160
|
def self._supported_host?
|
158
161
|
supported_hosts == :all ||
|
159
|
-
RbConfig::CONFIG[
|
162
|
+
RbConfig::CONFIG["host_os"] =~ /#{supported_hosts.join('|')}/
|
160
163
|
end
|
161
164
|
|
162
165
|
# Set or modify the `:title`, `:type` and `:image` options for a
|
@@ -169,7 +172,7 @@ module Guard
|
|
169
172
|
# @option opts [String] image the path to the notification image
|
170
173
|
#
|
171
174
|
def normalize_standard_options!(opts)
|
172
|
-
opts[:title] ||=
|
175
|
+
opts[:title] ||= "Guard"
|
173
176
|
opts[:type] ||= _notification_type(opts.fetch(:image, :success))
|
174
177
|
opts[:image] = _image_path(opts.delete(:image) { :success })
|
175
178
|
end
|
@@ -192,7 +195,7 @@ module Guard
|
|
192
195
|
def _image_path(image)
|
193
196
|
case image
|
194
197
|
when :failed, :pending, :success
|
195
|
-
images_path.join("#{image
|
198
|
+
images_path.join("#{image}.png").to_s
|
196
199
|
else
|
197
200
|
image
|
198
201
|
end
|
@@ -213,8 +216,6 @@ module Guard
|
|
213
216
|
:notify
|
214
217
|
end
|
215
218
|
end
|
216
|
-
|
217
219
|
end
|
218
|
-
|
219
220
|
end
|
220
221
|
end
|
@@ -1,25 +1,24 @@
|
|
1
|
-
require
|
1
|
+
require "guard/notifiers/base"
|
2
2
|
|
3
3
|
module Guard
|
4
4
|
module Notifier
|
5
|
-
|
6
|
-
#
|
5
|
+
# Send a notification to Emacs with emacsclient
|
6
|
+
# (http://www.emacswiki.org/emacs/EmacsClient).
|
7
7
|
#
|
8
8
|
# @example Add the `:emacs` notifier to your `Guardfile`
|
9
9
|
# notification :emacs
|
10
10
|
#
|
11
11
|
class Emacs < Base
|
12
|
-
|
13
12
|
DEFAULTS = {
|
14
|
-
client:
|
15
|
-
success:
|
16
|
-
failed:
|
17
|
-
default:
|
18
|
-
fontcolor:
|
13
|
+
client: "emacsclient",
|
14
|
+
success: "ForestGreen",
|
15
|
+
failed: "Firebrick",
|
16
|
+
default: "Black",
|
17
|
+
fontcolor: "White",
|
19
18
|
}
|
20
19
|
|
21
20
|
def self.available?(opts = {})
|
22
|
-
super
|
21
|
+
super && _emacs_client_available?(opts)
|
23
22
|
end
|
24
23
|
|
25
24
|
# @private
|
@@ -27,8 +26,10 @@ module Guard
|
|
27
26
|
# @return [Boolean] whether or not the emacs client is available
|
28
27
|
#
|
29
28
|
def self._emacs_client_available?(opts)
|
30
|
-
|
31
|
-
|
29
|
+
client_name = opts.fetch(:client, DEFAULTS[:client])
|
30
|
+
cmd = "#{client_name} --eval '1' 2> #{DEV_NULL} || echo 'N/A'"
|
31
|
+
stdout = Sheller.stdout(cmd)
|
32
|
+
!%w(N/A 'N/A').include?(stdout.chomp!)
|
32
33
|
end
|
33
34
|
|
34
35
|
# Shows a system notification.
|
@@ -58,13 +59,13 @@ module Guard
|
|
58
59
|
opts = DEFAULTS.merge(opts)
|
59
60
|
color = emacs_color(opts[:type], opts)
|
60
61
|
fontcolor = emacs_color(:fontcolor, opts)
|
61
|
-
elisp = <<-EOF.gsub(/\s+/,
|
62
|
+
elisp = <<-EOF.gsub(/\s+/, " ").strip
|
62
63
|
(set-face-attribute 'mode-line nil
|
63
64
|
:background "#{color}"
|
64
65
|
:foreground "#{fontcolor}")
|
65
66
|
EOF
|
66
67
|
|
67
|
-
_run_cmd(opts[:client],
|
68
|
+
_run_cmd(opts[:client], "--eval", elisp)
|
68
69
|
end
|
69
70
|
|
70
71
|
# Get the Emacs color for the notification type.
|
@@ -72,10 +73,19 @@ module Guard
|
|
72
73
|
#
|
73
74
|
# @param [String] type the notification type
|
74
75
|
# @param [Hash] options aditional notification options
|
75
|
-
#
|
76
|
-
# @option options [String]
|
77
|
-
#
|
78
|
-
#
|
76
|
+
#
|
77
|
+
# @option options [String] success the color to use for success
|
78
|
+
# notifications (default is 'ForestGreen')
|
79
|
+
#
|
80
|
+
# @option options [String] failed the color to use for failure
|
81
|
+
# notifications (default is 'Firebrick')
|
82
|
+
#
|
83
|
+
# @option options [String] pending the color to use for pending
|
84
|
+
# notifications
|
85
|
+
#
|
86
|
+
# @option options [String] default the default color to use (default is
|
87
|
+
# 'Black')
|
88
|
+
#
|
79
89
|
# @return [String] the name of the emacs color
|
80
90
|
#
|
81
91
|
def emacs_color(type, options = {})
|
@@ -85,13 +95,9 @@ module Guard
|
|
85
95
|
|
86
96
|
private
|
87
97
|
|
88
|
-
def _run_cmd(*args)
|
89
|
-
|
90
|
-
p.readlines
|
91
|
-
p.close
|
98
|
+
def _run_cmd(cmd, *args)
|
99
|
+
Sheller.run(cmd, *args)
|
92
100
|
end
|
93
|
-
|
94
101
|
end
|
95
|
-
|
96
102
|
end
|
97
103
|
end
|
@@ -1,15 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require "guard/notifiers/base"
|
2
2
|
|
3
3
|
module Guard
|
4
4
|
module Notifier
|
5
|
-
|
6
5
|
# Writes Guard notification results to a file.
|
7
6
|
#
|
8
7
|
# @example Add the `:file` notifier to your `Guardfile`
|
9
8
|
# notification :file, path: 'tmp/guard_result'
|
10
9
|
#
|
11
10
|
class FileNotifier < Base
|
12
|
-
|
13
11
|
DEFAULTS = {
|
14
12
|
format: "%s\n%s\n%s\n"
|
15
13
|
}
|
@@ -19,7 +17,7 @@ module Guard
|
|
19
17
|
# results will be written
|
20
18
|
#
|
21
19
|
def self.available?(opts = {})
|
22
|
-
super
|
20
|
+
super && opts.has_key?(:path)
|
23
21
|
end
|
24
22
|
|
25
23
|
# Writes the notification to a file. By default it writes type, title,
|
@@ -42,7 +40,7 @@ module Guard
|
|
42
40
|
|
43
41
|
_write(opts[:path], format % [opts[:type], opts[:title], message])
|
44
42
|
else
|
45
|
-
::Guard::UI.error
|
43
|
+
::Guard::UI.error ":file notifier requires a :path option"
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
@@ -51,8 +49,6 @@ module Guard
|
|
51
49
|
def _write(path, contents)
|
52
50
|
File.write(path, contents)
|
53
51
|
end
|
54
|
-
|
55
52
|
end
|
56
|
-
|
57
53
|
end
|
58
54
|
end
|