guard 2.9.0 → 2.9.1
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/lib/guard.rb +43 -160
- data/lib/guard/cli.rb +49 -17
- data/lib/guard/commander.rb +18 -17
- data/lib/guard/commands/all.rb +1 -2
- data/lib/guard/commands/change.rb +1 -2
- data/lib/guard/commands/reload.rb +1 -2
- data/lib/guard/commands/scope.rb +1 -2
- data/lib/guard/deprecated/evaluator.rb +34 -0
- data/lib/guard/deprecated/guard.rb +15 -3
- data/lib/guard/deprecated/watcher.rb +27 -0
- data/lib/guard/dsl.rb +58 -17
- data/lib/guard/dsl_describer.rb +55 -73
- data/lib/guard/guardfile.rb +1 -1
- data/lib/guard/guardfile/evaluator.rb +96 -158
- data/lib/guard/guardfile/generator.rb +45 -41
- data/lib/guard/interactor.rb +4 -2
- data/lib/guard/internals/groups.rb +40 -0
- data/lib/guard/internals/plugins.rb +51 -0
- data/lib/guard/internals/queue.rb +50 -0
- data/lib/guard/internals/scope.rb +110 -0
- data/lib/guard/internals/session.rb +135 -0
- data/lib/guard/internals/state.rb +33 -0
- data/lib/guard/jobs/pry_wrapper.rb +33 -32
- data/lib/guard/jobs/sleep.rb +3 -4
- data/lib/guard/notifier.rb +2 -0
- data/lib/guard/notifier/detected.rb.orig +83 -0
- data/lib/guard/plugin.rb +242 -6
- data/lib/guard/plugin_util.rb +19 -18
- data/lib/guard/reevaluator.rb +50 -10
- data/lib/guard/runner.rb +30 -108
- data/lib/guard/ui.rb +6 -24
- data/lib/guard/version.rb +1 -1
- data/lib/guard/watcher.rb +4 -12
- metadata +11 -6
- data/lib/guard/metadata.rb +0 -190
- data/lib/guard/plugin/base.rb +0 -183
- data/lib/guard/plugin/hooker.rb +0 -108
- data/lib/guard/session.rb +0 -5
data/lib/guard/plugin/base.rb
DELETED
@@ -1,183 +0,0 @@
|
|
1
|
-
require "guard/metadata"
|
2
|
-
|
3
|
-
module Guard
|
4
|
-
class Plugin
|
5
|
-
# Colection of shared methods between `Guard::Guard` (deprecated)
|
6
|
-
# and `Guard::Plugin`.
|
7
|
-
#
|
8
|
-
module Base
|
9
|
-
TEMPLATE_FORMAT = "%s/lib/guard/%s/templates/Guardfile"
|
10
|
-
|
11
|
-
require "guard/ui"
|
12
|
-
require "guard/plugin/hooker"
|
13
|
-
|
14
|
-
include ::Guard::Plugin::Hooker
|
15
|
-
|
16
|
-
attr_accessor :group, :watchers, :callbacks, :options
|
17
|
-
|
18
|
-
def self.included(base)
|
19
|
-
base.extend(ClassMethods)
|
20
|
-
end
|
21
|
-
|
22
|
-
module ClassMethods
|
23
|
-
# Returns the non-namespaced class name of the plugin
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# @example Non-namespaced class name for Guard::RSpec
|
27
|
-
# Guard::RSpec.non_namespaced_classname
|
28
|
-
# #=> "RSpec"
|
29
|
-
#
|
30
|
-
# @return [String]
|
31
|
-
#
|
32
|
-
def non_namespaced_classname
|
33
|
-
to_s.sub("Guard::", "")
|
34
|
-
end
|
35
|
-
|
36
|
-
# Returns the non-namespaced name of the plugin
|
37
|
-
#
|
38
|
-
#
|
39
|
-
# @example Non-namespaced name for Guard::RSpec
|
40
|
-
# Guard::RSpec.non_namespaced_name
|
41
|
-
# #=> "rspec"
|
42
|
-
#
|
43
|
-
# @return [String]
|
44
|
-
#
|
45
|
-
def non_namespaced_name
|
46
|
-
non_namespaced_classname.downcase
|
47
|
-
end
|
48
|
-
|
49
|
-
# Specify the source for the Guardfile template.
|
50
|
-
# Each Guard plugin can redefine this method to add its own logic.
|
51
|
-
#
|
52
|
-
# @param [String] plugin_location the plugin location
|
53
|
-
#
|
54
|
-
def template(plugin_location)
|
55
|
-
File.read TEMPLATE_FORMAT % [plugin_location, non_namespaced_name]
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Called once when Guard starts. Please override initialize method to
|
60
|
-
# init stuff.
|
61
|
-
#
|
62
|
-
# @raise [:task_has_failed] when start has failed
|
63
|
-
# @return [Object] the task result
|
64
|
-
#
|
65
|
-
# @!method start
|
66
|
-
|
67
|
-
# Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard
|
68
|
-
# quits).
|
69
|
-
#
|
70
|
-
# @raise [:task_has_failed] when stop has failed
|
71
|
-
# @return [Object] the task result
|
72
|
-
#
|
73
|
-
# @!method stop
|
74
|
-
|
75
|
-
# Called when `reload|r|z + enter` is pressed.
|
76
|
-
# This method should be mainly used for "reload" (really!) actions like
|
77
|
-
# reloading passenger/spork/bundler/...
|
78
|
-
#
|
79
|
-
# @raise [:task_has_failed] when reload has failed
|
80
|
-
# @return [Object] the task result
|
81
|
-
#
|
82
|
-
# @!method reload
|
83
|
-
|
84
|
-
# Called when just `enter` is pressed
|
85
|
-
# This method should be principally used for long action like running all
|
86
|
-
# specs/tests/...
|
87
|
-
#
|
88
|
-
# @raise [:task_has_failed] when run_all has failed
|
89
|
-
# @return [Object] the task result
|
90
|
-
#
|
91
|
-
# @!method run_all
|
92
|
-
|
93
|
-
# Default behaviour on file(s) changes that the Guard plugin watches.
|
94
|
-
#
|
95
|
-
# @param [Array<String>] paths the changes files or paths
|
96
|
-
# @raise [:task_has_failed] when run_on_changes has failed
|
97
|
-
# @return [Object] the task result
|
98
|
-
#
|
99
|
-
# @!method run_on_changes(paths)
|
100
|
-
|
101
|
-
# Called on file(s) additions that the Guard plugin watches.
|
102
|
-
#
|
103
|
-
# @param [Array<String>] paths the changes files or paths
|
104
|
-
# @raise [:task_has_failed] when run_on_additions has failed
|
105
|
-
# @return [Object] the task result
|
106
|
-
#
|
107
|
-
# @!method run_on_additions(paths)
|
108
|
-
|
109
|
-
# Called on file(s) modifications that the Guard plugin watches.
|
110
|
-
#
|
111
|
-
# @param [Array<String>] paths the changes files or paths
|
112
|
-
# @raise [:task_has_failed] when run_on_modifications has failed
|
113
|
-
# @return [Object] the task result
|
114
|
-
#
|
115
|
-
# @!method run_on_modifications(paths)
|
116
|
-
|
117
|
-
# Called on file(s) removals that the Guard plugin watches.
|
118
|
-
#
|
119
|
-
# @param [Array<String>] paths the changes files or paths
|
120
|
-
# @raise [:task_has_failed] when run_on_removals has failed
|
121
|
-
# @return [Object] the task result
|
122
|
-
#
|
123
|
-
# @!method run_on_removals(paths)
|
124
|
-
|
125
|
-
# Returns the plugin's name (without "guard-").
|
126
|
-
#
|
127
|
-
# @example Name for Guard::RSpec
|
128
|
-
# Guard::RSpec.new.name
|
129
|
-
# #=> "rspec"
|
130
|
-
#
|
131
|
-
# @return [String]
|
132
|
-
#
|
133
|
-
def name
|
134
|
-
@name ||= self.class.non_namespaced_name
|
135
|
-
end
|
136
|
-
|
137
|
-
# Returns the plugin's class name without the Guard:: namespace.
|
138
|
-
#
|
139
|
-
# @example Title for Guard::RSpec
|
140
|
-
# Guard::RSpec.new.title
|
141
|
-
# #=> "RSpec"
|
142
|
-
#
|
143
|
-
# @return [String]
|
144
|
-
#
|
145
|
-
def title
|
146
|
-
@title ||= self.class.non_namespaced_classname
|
147
|
-
end
|
148
|
-
|
149
|
-
# String representation of the plugin.
|
150
|
-
#
|
151
|
-
# @example String representation of an instance of the Guard::RSpec plugin
|
152
|
-
#
|
153
|
-
# Guard::RSpec.new.title
|
154
|
-
# #=> "#<Guard::RSpec @name=rspec @group=#<Guard::Group @name=default
|
155
|
-
# @options={}> @watchers=[] @callbacks=[] @options={all_after_pass:
|
156
|
-
# true}>"
|
157
|
-
#
|
158
|
-
# @return [String] the string representation
|
159
|
-
#
|
160
|
-
def to_s
|
161
|
-
"#<#{self.class} @name=#{name} @group=#{group} @watchers=#{watchers}"\
|
162
|
-
" @callbacks=#{callbacks} @options=#{options}>"
|
163
|
-
end
|
164
|
-
|
165
|
-
private
|
166
|
-
|
167
|
-
# Sets the @group, @watchers, @callbacks and @options variables from the
|
168
|
-
# given options hash.
|
169
|
-
#
|
170
|
-
# @param [Hash] options the Guard plugin options
|
171
|
-
#
|
172
|
-
# @see Guard::Plugin.initialize
|
173
|
-
#
|
174
|
-
def _set_instance_variables_from_options(options)
|
175
|
-
group_name = options.delete(:group) { :default }
|
176
|
-
@group = ::Guard.add_group(group_name)
|
177
|
-
@watchers = options.delete(:watchers) { [] }
|
178
|
-
@callbacks = options.delete(:callbacks) { [] }
|
179
|
-
@options = options
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
data/lib/guard/plugin/hooker.rb
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
module Guard
|
2
|
-
class Plugin
|
3
|
-
# Guard has a hook mechanism that allows you to insert callbacks for
|
4
|
-
# individual Guard plugins.
|
5
|
-
# By default, each of the Guard plugin instance methods has a "_begin" and
|
6
|
-
# an "_end" hook.
|
7
|
-
# For example, the Guard::Plugin#start method has a :start_begin hook that
|
8
|
-
# is runs immediately before Guard::Plugin#start, and a :start_end hook
|
9
|
-
# that runs immediately after Guard::Plugin#start.
|
10
|
-
#
|
11
|
-
# Read more about [hooks and callbacks on the
|
12
|
-
# wiki](https://github.com/guard/guard/wiki/Hooks-and-callbacks).
|
13
|
-
#
|
14
|
-
module Hooker
|
15
|
-
require "guard/ui"
|
16
|
-
|
17
|
-
# Get all callbacks registered for all Guard plugins present in the
|
18
|
-
# Guardfile.
|
19
|
-
#
|
20
|
-
def self.callbacks
|
21
|
-
@callbacks ||= Hash.new { |hash, key| hash[key] = [] }
|
22
|
-
end
|
23
|
-
|
24
|
-
# Add a callback.
|
25
|
-
#
|
26
|
-
# @param [Block] listener the listener to notify
|
27
|
-
# @param [Guard::Plugin] guard_plugin the Guard plugin to add the callback
|
28
|
-
# @param [Array<Symbol>] events the events to register
|
29
|
-
#
|
30
|
-
def self.add_callback(listener, guard_plugin, events)
|
31
|
-
Array(events).each do |event|
|
32
|
-
callbacks[[guard_plugin, event]] << listener
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Notify a callback.
|
37
|
-
#
|
38
|
-
# @param [Guard::Plugin] guard_plugin the Guard plugin to add the callback
|
39
|
-
# @param [Symbol] event the event to trigger
|
40
|
-
# @param [Array] args the arguments for the listener
|
41
|
-
#
|
42
|
-
def self.notify(guard_plugin, event, *args)
|
43
|
-
callbacks[[guard_plugin, event]].each do |listener|
|
44
|
-
listener.call(guard_plugin, event, *args)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# Reset all callbacks.
|
49
|
-
#
|
50
|
-
def self.reset_callbacks!
|
51
|
-
@callbacks = nil
|
52
|
-
end
|
53
|
-
|
54
|
-
# When event is a Symbol, {#hook} will generate a hook name
|
55
|
-
# by concatenating the method name from where {#hook} is called
|
56
|
-
# with the given Symbol.
|
57
|
-
#
|
58
|
-
# @example Add a hook with a Symbol
|
59
|
-
#
|
60
|
-
# def run_all
|
61
|
-
# hook :foo
|
62
|
-
# end
|
63
|
-
#
|
64
|
-
# Here, when {Guard::Plugin::Base#run_all} is called, {#hook} will notify
|
65
|
-
# callbacks registered for the "run_all_foo" event.
|
66
|
-
#
|
67
|
-
# When event is a String, {#hook} will directly turn the String
|
68
|
-
# into a Symbol.
|
69
|
-
#
|
70
|
-
# @example Add a hook with a String
|
71
|
-
#
|
72
|
-
# def run_all
|
73
|
-
# hook "foo_bar"
|
74
|
-
# end
|
75
|
-
#
|
76
|
-
# When {Guard::Plugin::Base#run_all} is called, {#hook} will notify
|
77
|
-
# callbacks registered for the "foo_bar" event.
|
78
|
-
#
|
79
|
-
# @param [Symbol, String] event the name of the Guard event
|
80
|
-
# @param [Array] args the parameters are passed as is to the callbacks
|
81
|
-
# registered for the given event.
|
82
|
-
#
|
83
|
-
def hook(event, *args)
|
84
|
-
hook_name = if event.is_a? Symbol
|
85
|
-
calling_method = caller[0][/`([^']*)'/, 1]
|
86
|
-
"#{ calling_method }_#{ event }"
|
87
|
-
else
|
88
|
-
event
|
89
|
-
end
|
90
|
-
|
91
|
-
::Guard::UI.debug "Hook :#{ hook_name } executed for #{ self.class }"
|
92
|
-
|
93
|
-
Hooker.notify(self, hook_name.to_sym, *args)
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
|
-
# Add all the Guard::Plugin's callbacks to the global @callbacks array
|
99
|
-
# that's used by Guard to know which callbacks to notify.
|
100
|
-
#
|
101
|
-
def _register_callbacks
|
102
|
-
callbacks.each do |callback|
|
103
|
-
Hooker.add_callback(callback[:listener], self, callback[:events])
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|