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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb89fd8c33c9157806648b93f82adc1756ae93d3
4
- data.tar.gz: 39596d5b723687f2e0aab7e31aeca974ee952af2
3
+ metadata.gz: a8af99f10f6df5f4ec30fda1e60627279c331afa
4
+ data.tar.gz: fab4128ccc9c311302c80270de736dbdaefacae1
5
5
  SHA512:
6
- metadata.gz: 33195a00ad0b4dfce3e70ab175254aba5a485e2eb8e5cf72ba601b34b31e948f5eb13c6f88a5bdfc6c200bf1b5d7c08d1c0a26f3658faf04c10d5fe54dea8f52
7
- data.tar.gz: 74db8ad59ac2ecda8d0c3cdd2aa2fcf9967ed3ef809ee0e0e5de1b523e6374b5f03d24c3feafa3b59519ac0eaa0dac8f9b6abb20f7c169497fed1aae8851b53f
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
- Guard plugins that don't belong to a group are considered global and are always run.
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
@@ -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
- raise ArgumentError, "'all' is not an allowed group name!" if name.to_sym == :all
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
- ::Guard.add_group(name, options)
124
- @current_group = name
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
- @current_group = nil
136
+ @current_groups.pop
129
137
  else
130
- ::Guard::UI.error "No Guard plugins found in the group '#{ name }', please add at least one."
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
- options.merge!(group: @current_group, watchers: @watchers, callbacks: @callbacks)
166
- ::Guard.add_plugin(name, options)
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.
@@ -86,7 +86,8 @@ module Guard
86
86
  private
87
87
 
88
88
  def _run_cmd(*args)
89
- p = IO.popen(args).readlines
89
+ p = IO.popen(args)
90
+ p.readlines
90
91
  p.close
91
92
  end
92
93
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Guard
2
- VERSION = '2.2.3'
2
+ VERSION = '2.2.4'
3
3
  end
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.3
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-04 00:00:00.000000000 Z
11
+ date: 2013-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor