guard 2.2.3 → 2.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -1
- data/lib/guard/dsl.rb +19 -9
- data/lib/guard/notifiers/emacs.rb +2 -1
- data/lib/guard/plugin/hooker.rb +67 -53
- data/lib/guard/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8af99f10f6df5f4ec30fda1e60627279c331afa
|
4
|
+
data.tar.gz: fab4128ccc9c311302c80270de736dbdaefacae1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eea1545a513b80dd36aed19b1f94189a8508bbe01c8e9ff1416807597dbd3a58e3b5df68f4e1c973d264160e861240aa999a87340aed6ca7369a80fddff61c84
|
7
|
+
data.tar.gz: d4d9c887f95c45cc671c7237d5c043eb2dd1b841d5b024f273260fda4164e8f080006a49bf7efe121997e3db9995831fd47360d24939f70a5be75a36ade05d95
|
data/README.md
CHANGED
@@ -478,13 +478,35 @@ group :docs do
|
|
478
478
|
end
|
479
479
|
```
|
480
480
|
|
481
|
+
Groups can be nested, reopened and can take muliple names to assign its plugin to multiple groups:
|
482
|
+
|
483
|
+
```ruby
|
484
|
+
group :desktop do
|
485
|
+
guard 'livereload' do
|
486
|
+
watch(%r{desktop/.+\.html})
|
487
|
+
end
|
488
|
+
|
489
|
+
group :mobile do
|
490
|
+
guard 'livereload' do
|
491
|
+
watch(%r{mobile/.+\.html})
|
492
|
+
end
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
group :mobile, :desktop do
|
497
|
+
guard 'livereload' do
|
498
|
+
watch(%r{both/.+\.html})
|
499
|
+
end
|
500
|
+
end
|
501
|
+
```
|
502
|
+
|
481
503
|
Groups to be run can be specified with the Guard DSL option `--group` (or `-g`):
|
482
504
|
|
483
505
|
```bash
|
484
506
|
$ bundle exec guard -g specs
|
485
507
|
```
|
486
508
|
|
487
|
-
|
509
|
+
Plugins that don't belong to a group are part of the `default` group.
|
488
510
|
|
489
511
|
Another neat use of groups is to group dependant plugins and stop processing if one fails. In order
|
490
512
|
to make this work, the group needs to have the `halt_on_fail` option enabled and the Guard plugin
|
data/lib/guard/dsl.rb
CHANGED
@@ -108,7 +108,7 @@ module Guard
|
|
108
108
|
# guard :livereload
|
109
109
|
# end
|
110
110
|
#
|
111
|
-
# @param [Symbol, String] name the group name called from the CLI
|
111
|
+
# @param [Symbol, String, Array<Symbol, String>] name the group name called from the CLI
|
112
112
|
# @param [Hash] options the options accepted by the group
|
113
113
|
# @yield a block where you can declare several Guard plugins
|
114
114
|
#
|
@@ -117,17 +117,25 @@ module Guard
|
|
117
117
|
# @see #guard
|
118
118
|
#
|
119
119
|
def group(name, options = {})
|
120
|
-
|
120
|
+
groups = Array(name)
|
121
|
+
|
122
|
+
groups.each do |group|
|
123
|
+
raise ArgumentError, "'all' is not an allowed group name!" if group.to_sym == :all
|
124
|
+
end
|
121
125
|
|
122
126
|
if block_given?
|
123
|
-
|
124
|
-
|
127
|
+
groups.each do |group|
|
128
|
+
::Guard.add_group(group, options)
|
129
|
+
end
|
130
|
+
|
131
|
+
@current_groups ||= []
|
132
|
+
@current_groups.push(groups)
|
125
133
|
|
126
134
|
yield
|
127
135
|
|
128
|
-
@
|
136
|
+
@current_groups.pop
|
129
137
|
else
|
130
|
-
::Guard::UI.error "No Guard plugins found in the group '#{
|
138
|
+
::Guard::UI.error "No Guard plugins found in the group '#{ groups.join(', ') }', please add at least one."
|
131
139
|
end
|
132
140
|
end
|
133
141
|
|
@@ -158,12 +166,14 @@ module Guard
|
|
158
166
|
def guard(name, options = {})
|
159
167
|
@watchers = []
|
160
168
|
@callbacks = []
|
161
|
-
@current_group ||= :default
|
162
169
|
|
163
170
|
yield if block_given?
|
164
171
|
|
165
|
-
|
166
|
-
|
172
|
+
groups = @current_groups || [[:default]]
|
173
|
+
groups.last.each do |group|
|
174
|
+
options.merge!(group: group, watchers: @watchers, callbacks: @callbacks)
|
175
|
+
::Guard.add_plugin(name, options)
|
176
|
+
end
|
167
177
|
end
|
168
178
|
|
169
179
|
# Defines a pattern to be watched in order to run actions on file modification.
|
data/lib/guard/plugin/hooker.rb
CHANGED
@@ -17,6 +17,73 @@ module Guard
|
|
17
17
|
|
18
18
|
require 'guard/ui'
|
19
19
|
|
20
|
+
# The Hooker module gets included.
|
21
|
+
#
|
22
|
+
# @param [Class] base the class that includes the module
|
23
|
+
#
|
24
|
+
def self.included(base)
|
25
|
+
base.send :include, InstanceMethods
|
26
|
+
end
|
27
|
+
|
28
|
+
# Instance methods that gets included in the base class.
|
29
|
+
#
|
30
|
+
module InstanceMethods
|
31
|
+
|
32
|
+
# When event is a Symbol, {#hook} will generate a hook name
|
33
|
+
# by concatenating the method name from where {#hook} is called
|
34
|
+
# with the given Symbol.
|
35
|
+
#
|
36
|
+
# @example Add a hook with a Symbol
|
37
|
+
#
|
38
|
+
# def run_all
|
39
|
+
# hook :foo
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# Here, when {Guard::Plugin::Base#run_all} is called, {#hook} will notify
|
43
|
+
# callbacks registered for the "run_all_foo" event.
|
44
|
+
#
|
45
|
+
# When event is a String, {#hook} will directly turn the String
|
46
|
+
# into a Symbol.
|
47
|
+
#
|
48
|
+
# @example Add a hook with a String
|
49
|
+
#
|
50
|
+
# def run_all
|
51
|
+
# hook "foo_bar"
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# When {Guard::Plugin::Base#run_all} is called, {#hook} will notify
|
55
|
+
# callbacks registered for the "foo_bar" event.
|
56
|
+
#
|
57
|
+
# @param [Symbol, String] event the name of the Guard event
|
58
|
+
# @param [Array] args the parameters are passed as is to the callbacks
|
59
|
+
# registered for the given event.
|
60
|
+
#
|
61
|
+
def hook(event, *args)
|
62
|
+
hook_name = if event.is_a? Symbol
|
63
|
+
calling_method = caller[0][/`([^']*)'/, 1]
|
64
|
+
"#{ calling_method }_#{ event }"
|
65
|
+
else
|
66
|
+
event
|
67
|
+
end
|
68
|
+
|
69
|
+
::Guard::UI.debug "Hook :#{ hook_name } executed for #{ self.class }"
|
70
|
+
|
71
|
+
Hooker.notify(self, hook_name.to_sym, *args)
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
# Add all the Guard::Plugin's callbacks to the global @callbacks array
|
77
|
+
# that's used by Guard to know which callbacks to notify.
|
78
|
+
#
|
79
|
+
def _register_callbacks
|
80
|
+
callbacks.each do |callback|
|
81
|
+
Hooker.add_callback(callback[:listener], self, callback[:events])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
20
87
|
# Get all callbacks registered for all Guard plugins present in the
|
21
88
|
# Guardfile.
|
22
89
|
#
|
@@ -65,59 +132,6 @@ module Guard
|
|
65
132
|
@callbacks = nil
|
66
133
|
end
|
67
134
|
|
68
|
-
# When event is a Symbol, {#hook} will generate a hook name
|
69
|
-
# by concatenating the method name from where {#hook} is called
|
70
|
-
# with the given Symbol.
|
71
|
-
#
|
72
|
-
# @example Add a hook with a Symbol
|
73
|
-
#
|
74
|
-
# def run_all
|
75
|
-
# hook :foo
|
76
|
-
# end
|
77
|
-
#
|
78
|
-
# Here, when {Guard::Plugin::Base#run_all} is called, {#hook} will notify
|
79
|
-
# callbacks registered for the "run_all_foo" event.
|
80
|
-
#
|
81
|
-
# When event is a String, {#hook} will directly turn the String
|
82
|
-
# into a Symbol.
|
83
|
-
#
|
84
|
-
# @example Add a hook with a String
|
85
|
-
#
|
86
|
-
# def run_all
|
87
|
-
# hook "foo_bar"
|
88
|
-
# end
|
89
|
-
#
|
90
|
-
# When {Guard::Plugin::Base#run_all} is called, {#hook} will notify
|
91
|
-
# callbacks registered for the "foo_bar" event.
|
92
|
-
#
|
93
|
-
# @param [Symbol, String] event the name of the Guard event
|
94
|
-
# @param [Array] args the parameters are passed as is to the callbacks
|
95
|
-
# registered for the given event.
|
96
|
-
#
|
97
|
-
def hook(event, *args)
|
98
|
-
hook_name = if event.is_a? Symbol
|
99
|
-
calling_method = caller[0][/`([^']*)'/, 1]
|
100
|
-
"#{ calling_method }_#{ event }"
|
101
|
-
else
|
102
|
-
event
|
103
|
-
end
|
104
|
-
|
105
|
-
::Guard::UI.debug "Hook :#{ hook_name } executed for #{ self.class }"
|
106
|
-
|
107
|
-
Hooker.notify(self, hook_name.to_sym, *args)
|
108
|
-
end
|
109
|
-
|
110
|
-
private
|
111
|
-
|
112
|
-
# Add all the Guard::Plugin's callbacks to the global @callbacks array
|
113
|
-
# that's used by Guard to know which callbacks to notify.
|
114
|
-
#
|
115
|
-
def _register_callbacks
|
116
|
-
callbacks.each do |callback|
|
117
|
-
self.class.add_callback(callback[:listener], self, callback[:events])
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
135
|
end
|
122
136
|
end
|
123
137
|
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.2.
|
4
|
+
version: 2.2.4
|
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: 2013-11-
|
11
|
+
date: 2013-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|