guard 2.9.1 → 2.9.2

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: d5b1ccadd885e53f1a8063e6f6d78038874115e7
4
- data.tar.gz: ed83d150185583201d3d6a76ebadc54172c94573
3
+ metadata.gz: e2893a48637334eddc679ffc6afeed7867611c0e
4
+ data.tar.gz: ddc0123c5b7bc8d0a63271ddb996c612b9f4d848
5
5
  SHA512:
6
- metadata.gz: 30542f519409c98e17fe922651fb5d461ed771803b46833fd918ae74576bc0e2b5aefe23ec60686d55408fe1bcba687fa587a2f569ae29ede158d915dbbfd0d7
7
- data.tar.gz: 8e352a2a2b4ec695b4ed2dd029bb5a1b46e38fcd308c2dddbcfcc007395b29498c7e0bbc28caec0c579482f1e3bd7326526f04a413f4a3ea972465cc7770383f
6
+ metadata.gz: acf4ff94539a63b66805573b16560b49fc8050b9561efce3a3cd358f14bb6e85f64c35eadc33d98f1cf4de0597cad56da9a0dbf5a6079ef46b341087dcac2b71
7
+ data.tar.gz: 1c6829ecc0fc789ea4fa6423cb96ed8251b223d0ed9d21421652683672ab72e37f47108c4354f100784b81a115e0b5e900a0b1e1ab57d84fc9462bb46e16e2a0
data/lib/guard/plugin.rb CHANGED
@@ -293,7 +293,7 @@ module Guard
293
293
  #
294
294
  def _register_callbacks
295
295
  callbacks.each do |callback|
296
- Hooker.add_callback(callback[:listener], self, callback[:events])
296
+ self.class.add_callback(callback[:listener], self, callback[:events])
297
297
  end
298
298
  end
299
299
  end
@@ -0,0 +1,300 @@
1
+ module Guard
2
+ # Base class from which every Guard plugin implementation must inherit.
3
+ #
4
+ # Guard will trigger the {#start}, {#stop}, {#reload}, {#run_all} and
5
+ # {#run_on_changes} ({#run_on_additions}, {#run_on_modifications} and
6
+ # {#run_on_removals}) task methods depending on user interaction and file
7
+ # modification.
8
+ #
9
+ # {#run_on_changes} could be implemented to handle all the changes task case
10
+ # (additions, modifications, removals) in once, or each task can be
11
+ # implemented separately with a specific behavior.
12
+ #
13
+ # In each of these Guard task methods you have to implement some work when
14
+ # you want to support this kind of task. The return value of each Guard task
15
+ # method is not evaluated by Guard, but it'll be passed to the "_end" hook
16
+ # for further evaluation. You can throw `:task_has_failed` to indicate that
17
+ # your Guard plugin method was not successful, and successive Guard plugin
18
+ # tasks will be aborted when the group has set the `:halt_on_fail` option.
19
+ #
20
+ # @see Guard::Group
21
+ #
22
+ # @example Throw :task_has_failed
23
+ #
24
+ # def run_all
25
+ # if !runner.run(['all'])
26
+ # throw :task_has_failed
27
+ # end
28
+ # end
29
+ #
30
+ # Each Guard plugin should provide a template Guardfile located within the Gem
31
+ # at `lib/guard/guard-name/templates/Guardfile`.
32
+ #
33
+ # Watchers for a Guard plugin should return a file path or an array of files
34
+ # paths to Guard, but if your Guard plugin wants to allow any return value
35
+ # from a watcher, you can set the `any_return` option to true.
36
+ #
37
+ # If one of those methods raises an exception other than `:task_has_failed`,
38
+ # the `Guard::GuardName` instance will be removed from the active Guard
39
+ # plugins.
40
+ #
41
+ class Plugin
42
+ TEMPLATE_FORMAT = "%s/lib/guard/%s/templates/Guardfile"
43
+
44
+ require "guard/ui"
45
+
46
+ # Get all callbacks registered for all Guard plugins present in the
47
+ # Guardfile.
48
+ #
49
+ def self.callbacks
50
+ @callbacks ||= Hash.new { |hash, key| hash[key] = [] }
51
+ end
52
+
53
+ # Add a callback.
54
+ #
55
+ # @param [Block] listener the listener to notify
56
+ # @param [Guard::Plugin] guard_plugin the Guard plugin to add the callback
57
+ # @param [Array<Symbol>] events the events to register
58
+ #
59
+ def self.add_callback(listener, guard_plugin, events)
60
+ Array(events).each do |event|
61
+ callbacks[[guard_plugin, event]] << listener
62
+ end
63
+ end
64
+
65
+ # Notify a callback.
66
+ #
67
+ # @param [Guard::Plugin] guard_plugin the Guard plugin to add the callback
68
+ # @param [Symbol] event the event to trigger
69
+ # @param [Array] args the arguments for the listener
70
+ #
71
+ def self.notify(guard_plugin, event, *args)
72
+ callbacks[[guard_plugin, event]].each do |listener|
73
+ listener.call(guard_plugin, event, *args)
74
+ end
75
+ end
76
+
77
+ # Reset all callbacks.
78
+ #
79
+ # TODO: remove (not used anywhere)
80
+ def self.reset_callbacks!
81
+ @callbacks = nil
82
+ end
83
+
84
+ # When event is a Symbol, {#hook} will generate a hook name
85
+ # by concatenating the method name from where {#hook} is called
86
+ # with the given Symbol.
87
+ #
88
+ # @example Add a hook with a Symbol
89
+ #
90
+ # def run_all
91
+ # hook :foo
92
+ # end
93
+ #
94
+ # Here, when {Guard::Plugin::Base#run_all} is called, {#hook} will notify
95
+ # callbacks registered for the "run_all_foo" event.
96
+ #
97
+ # When event is a String, {#hook} will directly turn the String
98
+ # into a Symbol.
99
+ #
100
+ # @example Add a hook with a String
101
+ #
102
+ # def run_all
103
+ # hook "foo_bar"
104
+ # end
105
+ #
106
+ # When {Guard::Plugin::Base#run_all} is called, {#hook} will notify
107
+ # callbacks registered for the "foo_bar" event.
108
+ #
109
+ # @param [Symbol, String] event the name of the Guard event
110
+ # @param [Array] args the parameters are passed as is to the callbacks
111
+ # registered for the given event.
112
+ #
113
+ def hook(event, *args)
114
+ hook_name = if event.is_a? Symbol
115
+ calling_method = caller[0][/`([^']*)'/, 1]
116
+ "#{ calling_method }_#{ event }"
117
+ else
118
+ event
119
+ end
120
+
121
+ UI.debug "Hook :#{ hook_name } executed for #{ self.class }"
122
+
123
+ self.class.notify(self, hook_name.to_sym, *args)
124
+ end
125
+
126
+ attr_accessor :group, :watchers, :callbacks, :options
127
+
128
+ # Returns the non-namespaced class name of the plugin
129
+ #
130
+ #
131
+ # @example Non-namespaced class name for Guard::RSpec
132
+ # Guard::RSpec.non_namespaced_classname
133
+ # #=> "RSpec"
134
+ #
135
+ # @return [String]
136
+ #
137
+ def self.non_namespaced_classname
138
+ to_s.sub("Guard::", "")
139
+ end
140
+
141
+ # Returns the non-namespaced name of the plugin
142
+ #
143
+ #
144
+ # @example Non-namespaced name for Guard::RSpec
145
+ # Guard::RSpec.non_namespaced_name
146
+ # #=> "rspec"
147
+ #
148
+ # @return [String]
149
+ #
150
+ def self.non_namespaced_name
151
+ non_namespaced_classname.downcase
152
+ end
153
+
154
+ # Specify the source for the Guardfile template.
155
+ # Each Guard plugin can redefine this method to add its own logic.
156
+ #
157
+ # @param [String] plugin_location the plugin location
158
+ #
159
+ def self.template(plugin_location)
160
+ File.read TEMPLATE_FORMAT % [plugin_location, non_namespaced_name]
161
+ end
162
+
163
+ # Called once when Guard starts. Please override initialize method to
164
+ # init stuff.
165
+ #
166
+ # @raise [:task_has_failed] when start has failed
167
+ # @return [Object] the task result
168
+ #
169
+ # @!method start
170
+
171
+ # Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard
172
+ # quits).
173
+ #
174
+ # @raise [:task_has_failed] when stop has failed
175
+ # @return [Object] the task result
176
+ #
177
+ # @!method stop
178
+
179
+ # Called when `reload|r|z + enter` is pressed.
180
+ # This method should be mainly used for "reload" (really!) actions like
181
+ # reloading passenger/spork/bundler/...
182
+ #
183
+ # @raise [:task_has_failed] when reload has failed
184
+ # @return [Object] the task result
185
+ #
186
+ # @!method reload
187
+
188
+ # Called when just `enter` is pressed
189
+ # This method should be principally used for long action like running all
190
+ # specs/tests/...
191
+ #
192
+ # @raise [:task_has_failed] when run_all has failed
193
+ # @return [Object] the task result
194
+ #
195
+ # @!method run_all
196
+
197
+ # Default behaviour on file(s) changes that the Guard plugin watches.
198
+ #
199
+ # @param [Array<String>] paths the changes files or paths
200
+ # @raise [:task_has_failed] when run_on_changes has failed
201
+ # @return [Object] the task result
202
+ #
203
+ # @!method run_on_changes(paths)
204
+
205
+ # Called on file(s) additions that the Guard plugin watches.
206
+ #
207
+ # @param [Array<String>] paths the changes files or paths
208
+ # @raise [:task_has_failed] when run_on_additions has failed
209
+ # @return [Object] the task result
210
+ #
211
+ # @!method run_on_additions(paths)
212
+
213
+ # Called on file(s) modifications that the Guard plugin watches.
214
+ #
215
+ # @param [Array<String>] paths the changes files or paths
216
+ # @raise [:task_has_failed] when run_on_modifications has failed
217
+ # @return [Object] the task result
218
+ #
219
+ # @!method run_on_modifications(paths)
220
+
221
+ # Called on file(s) removals that the Guard plugin watches.
222
+ #
223
+ # @param [Array<String>] paths the changes files or paths
224
+ # @raise [:task_has_failed] when run_on_removals has failed
225
+ # @return [Object] the task result
226
+ #
227
+ # @!method run_on_removals(paths)
228
+
229
+ # Returns the plugin's name (without "guard-").
230
+ #
231
+ # @example Name for Guard::RSpec
232
+ # Guard::RSpec.new.name
233
+ # #=> "rspec"
234
+ #
235
+ # @return [String]
236
+ #
237
+ def name
238
+ @name ||= self.class.non_namespaced_name
239
+ end
240
+
241
+ # Returns the plugin's class name without the Guard:: namespace.
242
+ #
243
+ # @example Title for Guard::RSpec
244
+ # Guard::RSpec.new.title
245
+ # #=> "RSpec"
246
+ #
247
+ # @return [String]
248
+ #
249
+ def title
250
+ @title ||= self.class.non_namespaced_classname
251
+ end
252
+
253
+ # String representation of the plugin.
254
+ #
255
+ # @example String representation of an instance of the Guard::RSpec plugin
256
+ #
257
+ # Guard::RSpec.new.title
258
+ # #=> "#<Guard::RSpec @name=rspec @group=#<Guard::Group @name=default
259
+ # @options={}> @watchers=[] @callbacks=[] @options={all_after_pass:
260
+ # true}>"
261
+ #
262
+ # @return [String] the string representation
263
+ #
264
+ def to_s
265
+ "#<#{self.class} @name=#{name} @group=#{group} @watchers=#{watchers}"\
266
+ " @callbacks=#{callbacks} @options=#{options}>"
267
+ end
268
+
269
+ private
270
+
271
+ # Initializes a Guard plugin.
272
+ # Don't do any work here, especially as Guard plugins get initialized even
273
+ # if they are not in an active group!
274
+ #
275
+ # @param [Hash] options the Guard plugin options
276
+ # @option options [Array<Guard::Watcher>] watchers the Guard plugin file
277
+ # watchers
278
+ # @option options [Symbol] group the group this Guard plugin belongs to
279
+ # @option options [Boolean] any_return allow any object to be returned from
280
+ # a watcher
281
+ #
282
+ def initialize(options = {})
283
+ group_name = options.delete(:group) { :default }
284
+ @group = Guard.state.session.groups.add(group_name)
285
+ @watchers = options.delete(:watchers) { [] }
286
+ @callbacks = options.delete(:callbacks) { [] }
287
+ @options = options
288
+ _register_callbacks
289
+ end
290
+
291
+ # Add all the Guard::Plugin's callbacks to the global @callbacks array
292
+ # that's used by Guard to know which callbacks to notify.
293
+ #
294
+ def _register_callbacks
295
+ callbacks.each do |callback|
296
+ Hooker.add_callback(callback[:listener], self, callback[:events])
297
+ end
298
+ end
299
+ end
300
+ end
data/lib/guard/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Guard
2
- VERSION = "2.9.1"
2
+ VERSION = "2.9.2"
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.9.1
4
+ version: 2.9.2
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-28 00:00:00.000000000 Z
11
+ date: 2014-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -155,6 +155,7 @@ files:
155
155
  - lib/guard/notifiers/tmux.rb
156
156
  - lib/guard/options.rb
157
157
  - lib/guard/plugin.rb
158
+ - lib/guard/plugin.rb.orig
158
159
  - lib/guard/plugin_util.rb
159
160
  - lib/guard/rake_task.rb
160
161
  - lib/guard/reevaluator.rb