guard 2.5.1 → 2.6.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.
- checksums.yaml +4 -4
- data/LICENSE +2 -0
- data/README.md +12 -3
- data/lib/guard/dsl.rb +15 -6
- data/lib/guard/guardfile/evaluator.rb +37 -47
- data/lib/guard/notifiers/tmux.rb +14 -15
- data/lib/guard/version.rb +1 -1
- metadata +4 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 949af1dc04bc3ed850cf0b63fd523bc1ddb3316a
|
4
|
+
data.tar.gz: a200da636376286362b7c8c06bfe48586c52124b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 409a80a8cf1172d1d077e5a147d26a2dc91f4d90e0adcb17b1fbbe183e6404b087e91294536c3d94448ed0cc59f63bd2b30f2c21275e80fea34bd4ab17c7bece
|
7
|
+
data.tar.gz: 6642c59beed12c1b3bddd5eb93b3e8579a56a85f4c531ede1c193811feb1b3d32f96b0164b4c982c467dba2f3fbc15a4b1ee8b5508006c6f7af48398f8fd6b4f
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
Guard
|
1
|
+
Guard
|
2
2
|
=====
|
3
3
|
|
4
|
+
[](http://badge.fury.io/rb/guard) [](https://travis-ci.org/guard/guard) [](https://gemnasium.com/guard/guard) [](https://codeclimate.com/github/guard/guard) [](https://coveralls.io/r/guard/guard) [](http://inch-pages.github.io/github/guard/guard)
|
5
|
+
|
4
6
|
<img src="http://cl.ly/image/1k3o1r2Z3a0J/guard-Icon.png" alt="Guard Icon" align="right" />
|
5
7
|
Guard is a command line tool to easily handle events on file system modifications.
|
6
8
|
|
@@ -399,7 +401,7 @@ more detailed information. `help guard` will show all Guard related commands ava
|
|
399
401
|
|
400
402
|
Pry supports the Ruby built-in Readline, [rb-readline](https://github.com/luislavena/rb-readline) and
|
401
403
|
[Coolline](https://github.com/Mon-Ouie/coolline). Just install the readline implementation of your choice by adding it
|
402
|
-
to your `Gemfile
|
404
|
+
to your `Gemfile`.
|
403
405
|
|
404
406
|
You can also disable the interactions completely by running Guard with the `--no-interactions` option.
|
405
407
|
|
@@ -492,10 +494,17 @@ You can also launch any arbitrary command in the supplied block:
|
|
492
494
|
|
493
495
|
```ruby
|
494
496
|
guard :shell do
|
495
|
-
watch(
|
497
|
+
watch(/.*/) { `git status` }
|
496
498
|
end
|
497
499
|
```
|
498
500
|
|
501
|
+
You can also define `watch`es outside of a `guard` plugin. This is useful to perform arbitrary Ruby
|
502
|
+
logic (i.e. something project-specific).
|
503
|
+
|
504
|
+
```ruby
|
505
|
+
watch(/.*/) { |m| puts "#{m[0]} changed." }
|
506
|
+
```
|
507
|
+
|
499
508
|
### group
|
500
509
|
|
501
510
|
The `group` method allows you to group several plugins together. This comes in handy especially when you
|
data/lib/guard/dsl.rb
CHANGED
@@ -165,16 +165,16 @@ module Guard
|
|
165
165
|
# @see #group
|
166
166
|
#
|
167
167
|
def guard(name, options = {})
|
168
|
-
@
|
169
|
-
@callbacks = []
|
168
|
+
@plugin_options = options.merge(watchers: [], callbacks: [])
|
170
169
|
|
171
170
|
yield if block_given?
|
172
171
|
|
173
172
|
groups = @current_groups && @current_groups.last || [:default]
|
174
173
|
groups.each do |group|
|
175
|
-
|
176
|
-
::Guard.add_plugin(name, options)
|
174
|
+
::Guard.add_plugin(name, @plugin_options.merge(group: group))
|
177
175
|
end
|
176
|
+
|
177
|
+
@plugin_options = nil
|
178
178
|
end
|
179
179
|
|
180
180
|
# Defines a pattern to be watched in order to run actions on file modification.
|
@@ -186,6 +186,9 @@ module Guard
|
|
186
186
|
# watch(%r{^app/controllers/(.+).rb}) { |m| 'spec/acceptance/#{m[1]}s_spec.rb' }
|
187
187
|
# end
|
188
188
|
#
|
189
|
+
# @example Declare global watchers outside of a Guard
|
190
|
+
# watch(%r{^(.+)$}) { |m| puts "#{m[1]} changed." }
|
191
|
+
#
|
189
192
|
# @param [String, Regexp] pattern the pattern that Guard must watch for modification
|
190
193
|
# @yield a block to be run when the pattern is matched
|
191
194
|
# @yieldparam [MatchData] m matches of the pattern
|
@@ -195,7 +198,11 @@ module Guard
|
|
195
198
|
# @see #guard
|
196
199
|
#
|
197
200
|
def watch(pattern, &action)
|
198
|
-
|
201
|
+
# Allow watches in the global scope (to execute arbitrary commands) by
|
202
|
+
# building a generic Guard::Plugin.
|
203
|
+
return guard(:plugin) { watch(pattern, &action) } unless @plugin_options
|
204
|
+
|
205
|
+
@plugin_options[:watchers] << ::Guard::Watcher.new(pattern, action)
|
199
206
|
end
|
200
207
|
|
201
208
|
# Defines a callback to execute arbitrary code before or after any of
|
@@ -216,6 +223,8 @@ module Guard
|
|
216
223
|
# @see Guard::Hooker
|
217
224
|
#
|
218
225
|
def callback(*args, &block)
|
226
|
+
fail "callback must be called within a guard block" unless @plugin_options
|
227
|
+
|
219
228
|
block, events = if args.size > 1
|
220
229
|
# block must be the first argument in that case, the yielded block is
|
221
230
|
# ignored
|
@@ -223,7 +232,7 @@ module Guard
|
|
223
232
|
else
|
224
233
|
[block, args[0]]
|
225
234
|
end
|
226
|
-
@callbacks << { events: events, listener: block }
|
235
|
+
@plugin_options[:callbacks] << { events: events, listener: block }
|
227
236
|
end
|
228
237
|
|
229
238
|
# Ignores certain paths globally.
|
@@ -10,7 +10,7 @@ module Guard
|
|
10
10
|
#
|
11
11
|
class Evaluator
|
12
12
|
|
13
|
-
attr_reader :options
|
13
|
+
attr_reader :options, :guardfile_source, :guardfile_path
|
14
14
|
|
15
15
|
# Initializes a new Guard::Guardfile::Evaluator object.
|
16
16
|
#
|
@@ -41,6 +41,9 @@ module Guard
|
|
41
41
|
# the current Guard configuration.
|
42
42
|
#
|
43
43
|
def reevaluate_guardfile
|
44
|
+
# Don't re-evaluate inline Guardfile
|
45
|
+
return if @guardfile_source == :inline
|
46
|
+
|
44
47
|
_before_reevaluate_guardfile
|
45
48
|
evaluate_guardfile
|
46
49
|
_after_reevaluate_guardfile
|
@@ -50,10 +53,10 @@ module Guard
|
|
50
53
|
#
|
51
54
|
# @example Programmatically test if a Guardfile contains a specific Guard plugin
|
52
55
|
# File.read('Guardfile')
|
53
|
-
#
|
56
|
+
# => "guard :rspec"
|
54
57
|
#
|
55
58
|
# Guard::Guardfile::Evaluator.new.guardfile_include?('rspec)
|
56
|
-
#
|
59
|
+
# => true
|
57
60
|
#
|
58
61
|
# @param [String] plugin_name the name of the Guard
|
59
62
|
# @return [Boolean] whether the Guard plugin has been declared
|
@@ -62,39 +65,12 @@ module Guard
|
|
62
65
|
_guardfile_contents_without_user_config.match(/^guard\s*\(?\s*['":]#{ plugin_name }['"]?/)
|
63
66
|
end
|
64
67
|
|
65
|
-
# Gets the file path to the project `Guardfile`.
|
66
|
-
#
|
67
|
-
# @example Gets the path of the currently evaluated Guardfile
|
68
|
-
# Dir.pwd
|
69
|
-
# #=> "/Users/remy/Code/github/guard"
|
70
|
-
#
|
71
|
-
# evaluator = Guard::Guardfile::Evaluator.new
|
72
|
-
# evaluator.evaluate_guardfile
|
73
|
-
# #=> nil
|
74
|
-
#
|
75
|
-
# evaluator.guardfile_path
|
76
|
-
# #=> "/Users/remy/Code/github/guard/Guardfile"
|
77
|
-
#
|
78
|
-
# @example Gets the "path" of an inline Guardfile
|
79
|
-
# > Guard::Guardfile::Evaluator.new(guardfile_contents: 'guard :rspec').evaluate_guardfile
|
80
|
-
# => nil
|
81
|
-
#
|
82
|
-
# > Guard::Guardfile::Evaluator.new.guardfile_path
|
83
|
-
# => "Inline Guardfile"
|
84
|
-
#
|
85
|
-
# @return [String] the path to the Guardfile or 'Inline Guardfile' if
|
86
|
-
# the Guardfile has been specified via the `:guardfile_contents` option.
|
87
|
-
#
|
88
|
-
def guardfile_path
|
89
|
-
options[:guardfile_path] || ''
|
90
|
-
end
|
91
|
-
|
92
68
|
# Gets the content of the `Guardfile` concatenated with the global
|
93
69
|
# user configuration file.
|
94
70
|
#
|
95
71
|
# @example Programmatically get the content of the current Guardfile
|
96
72
|
# Guard::Guardfile::Evaluator.new.guardfile_contents
|
97
|
-
#
|
73
|
+
# => "guard :rspec"
|
98
74
|
#
|
99
75
|
# @return [String] the Guardfile content
|
100
76
|
#
|
@@ -110,7 +86,7 @@ module Guard
|
|
110
86
|
# @return [String] the Guardfile content
|
111
87
|
#
|
112
88
|
def _guardfile_contents_without_user_config
|
113
|
-
|
89
|
+
@guardfile_contents || ''
|
114
90
|
end
|
115
91
|
|
116
92
|
# Evaluates the content of the `Guardfile`.
|
@@ -118,14 +94,13 @@ module Guard
|
|
118
94
|
# @param [String] contents the content to evaluate.
|
119
95
|
#
|
120
96
|
def _instance_eval_guardfile(contents)
|
121
|
-
::Guard::Dsl.new.instance_eval(contents,
|
97
|
+
::Guard::Dsl.new.instance_eval(contents, @guardfile_path || '', 1)
|
122
98
|
rescue => ex
|
123
99
|
::Guard::UI.error "Invalid Guardfile, original error is:\n#{ $! }"
|
124
100
|
raise ex
|
125
101
|
end
|
126
102
|
|
127
|
-
# Gets the content to evaluate and stores it into
|
128
|
-
# the options as `:guardfile_contents`.
|
103
|
+
# Gets the content to evaluate and stores it into @guardfile_contents.
|
129
104
|
#
|
130
105
|
def _fetch_guardfile_contents
|
131
106
|
_use_inline_guardfile || _use_provided_guardfile || _use_default_guardfile
|
@@ -138,26 +113,40 @@ module Guard
|
|
138
113
|
# Use the provided inline Guardfile if provided.
|
139
114
|
#
|
140
115
|
def _use_inline_guardfile
|
141
|
-
|
116
|
+
if (@guardfile_source.nil? && options[:guardfile_contents]) || @guardfile_source == :inline
|
117
|
+
|
118
|
+
@guardfile_source = :inline
|
119
|
+
@guardfile_contents = options[:guardfile_contents]
|
120
|
+
|
121
|
+
::Guard::UI.info 'Using inline Guardfile.'
|
142
122
|
|
143
|
-
|
144
|
-
|
123
|
+
true
|
124
|
+
else
|
125
|
+
false
|
126
|
+
end
|
145
127
|
end
|
146
128
|
|
147
129
|
# Try to use the provided Guardfile. Exits Guard if the Guardfile cannot
|
148
130
|
# be found.
|
149
131
|
#
|
150
132
|
def _use_provided_guardfile
|
151
|
-
|
133
|
+
if (@guardfile_source.nil? && options[:guardfile]) || @guardfile_source == :custom
|
134
|
+
|
135
|
+
@guardfile_source = :custom
|
136
|
+
|
137
|
+
options[:guardfile] = File.expand_path(options[:guardfile])
|
138
|
+
if File.exist?(options[:guardfile])
|
139
|
+
_read_guardfile(options[:guardfile])
|
140
|
+
::Guard::UI.info "Using Guardfile at #{ options[:guardfile] }."
|
141
|
+
true
|
142
|
+
else
|
143
|
+
::Guard::UI.error "No Guardfile exists at #{ options[:guardfile] }."
|
144
|
+
exit 1
|
145
|
+
end
|
152
146
|
|
153
|
-
options[:guardfile] = File.expand_path(options[:guardfile])
|
154
|
-
if File.exist?(options[:guardfile])
|
155
|
-
_read_guardfile(options[:guardfile])
|
156
|
-
::Guard::UI.info "Using Guardfile at #{ options[:guardfile] }."
|
157
147
|
true
|
158
148
|
else
|
159
|
-
|
160
|
-
exit 1
|
149
|
+
false
|
161
150
|
end
|
162
151
|
end
|
163
152
|
|
@@ -166,6 +155,7 @@ module Guard
|
|
166
155
|
#
|
167
156
|
def _use_default_guardfile
|
168
157
|
if guardfile_path = _find_default_guardfile
|
158
|
+
@guardfile_source = :default
|
169
159
|
_read_guardfile(guardfile_path)
|
170
160
|
else
|
171
161
|
::Guard::UI.error 'No Guardfile found, please create one with `guard init`.'
|
@@ -185,8 +175,8 @@ module Guard
|
|
185
175
|
# @param [String] guardfile_path the path to the Guardfile
|
186
176
|
#
|
187
177
|
def _read_guardfile(guardfile_path)
|
188
|
-
|
189
|
-
|
178
|
+
@guardfile_path = guardfile_path
|
179
|
+
@guardfile_contents = File.read(guardfile_path)
|
190
180
|
rescue => ex
|
191
181
|
::Guard::UI.error "Error reading file #{ guardfile_path }:"
|
192
182
|
::Guard::UI.error ex.inspect
|
data/lib/guard/notifiers/tmux.rb
CHANGED
@@ -204,9 +204,10 @@ module Guard
|
|
204
204
|
# Notification starting, save the current Tmux settings
|
205
205
|
# and quiet the Tmux output.
|
206
206
|
#
|
207
|
-
def turn_on
|
207
|
+
def self.turn_on
|
208
208
|
unless @options_stored
|
209
209
|
_reset_options_store
|
210
|
+
|
210
211
|
_clients.each do |client|
|
211
212
|
options_store[client] ||= {}
|
212
213
|
`#{ DEFAULTS[:client] } show -t #{ client }`.each_line do |line|
|
@@ -214,6 +215,7 @@ module Guard
|
|
214
215
|
@options_store[client][option] = setting
|
215
216
|
end
|
216
217
|
end
|
218
|
+
|
217
219
|
@options_stored = true
|
218
220
|
end
|
219
221
|
end
|
@@ -222,7 +224,7 @@ module Guard
|
|
222
224
|
# if available (existing options are restored, new options
|
223
225
|
# are unset) and unquiet the Tmux output.
|
224
226
|
#
|
225
|
-
def turn_off
|
227
|
+
def self.turn_off
|
226
228
|
if @options_stored
|
227
229
|
@options_store.each do |client, options|
|
228
230
|
options.each do |key, value|
|
@@ -237,7 +239,7 @@ module Guard
|
|
237
239
|
end
|
238
240
|
end
|
239
241
|
|
240
|
-
def options_store
|
242
|
+
def self.options_store
|
241
243
|
@options_store ||= {}
|
242
244
|
end
|
243
245
|
|
@@ -248,8 +250,12 @@ module Guard
|
|
248
250
|
super
|
249
251
|
end
|
250
252
|
|
253
|
+
def self._clients
|
254
|
+
`#{ DEFAULTS[:client] } list-clients -F '\#{ client_tty }'`.split(/\n/)
|
255
|
+
end
|
256
|
+
|
251
257
|
def _clients
|
252
|
-
|
258
|
+
self.class._client
|
253
259
|
end
|
254
260
|
|
255
261
|
def _run_client(cmd, args)
|
@@ -271,10 +277,11 @@ module Guard
|
|
271
277
|
|
272
278
|
# Reset the internal Tmux options store defaults.
|
273
279
|
#
|
274
|
-
def _reset_options_store
|
280
|
+
def self._reset_options_store
|
275
281
|
@options_stored = false
|
276
282
|
@options_store = {}
|
277
|
-
|
283
|
+
|
284
|
+
_clients.each do |client|
|
278
285
|
@options_store[client] = {
|
279
286
|
'status-left-bg' => nil,
|
280
287
|
'status-right-bg' => nil,
|
@@ -287,16 +294,8 @@ module Guard
|
|
287
294
|
end
|
288
295
|
end
|
289
296
|
|
290
|
-
# Remove clients which no longer exist from options store
|
291
|
-
#
|
292
|
-
def _remove_old_clients
|
293
|
-
(options_store.keys - _clients).each do | old_client |
|
294
|
-
options_store.delete old_client
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
297
|
def _tmux_version
|
299
|
-
@tmux_version ||= `tmux -V`.chomp.gsub(/[^0-9.]/,'').to_f
|
298
|
+
@tmux_version ||= `tmux -V`.chomp.gsub(/[^0-9.]/, '').to_f
|
300
299
|
end
|
301
300
|
|
302
301
|
end
|
data/lib/guard/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibaud Guillaume-Gentil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '2.
|
33
|
+
version: '2.7'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '2.
|
40
|
+
version: '2.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,34 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.2.4
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: bundler
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rspec
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - '='
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 3.0.0.beta1
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - '='
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 3.0.0.beta1
|
111
83
|
description: Guard is a command line tool to easily handle events on file system modifications.
|
112
84
|
email:
|
113
85
|
- thibaud@thibaud.gg
|