guard 2.10.2 → 2.10.3

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.
@@ -17,7 +17,7 @@ module Guard
17
17
  BANNER
18
18
 
19
19
  def process(*entries)
20
- scope, unknown = ::Guard::Interactor.convert_scope(entries)
20
+ scope, unknown = Guard.state.session.convert_scope(entries)
21
21
 
22
22
  unless unknown.empty?
23
23
  output.puts "Unknown scopes: #{unknown.join(",") }"
@@ -1,24 +1,18 @@
1
- require "guard/internals/environment"
1
+ require "nenv"
2
2
 
3
3
  module Guard
4
- class Config
5
- def strict?
6
- _env.strict?
7
- end
8
-
9
- def silence_deprecations?
10
- end
11
-
12
- private
4
+ config_class = Nenv::Builder.build do
5
+ create_method(:strict?)
6
+ create_method(:gem_silence_deprecations?)
7
+ end
13
8
 
14
- def _env
15
- @env ||= _create_env
9
+ class Config < config_class
10
+ def initialize
11
+ super "guard"
16
12
  end
17
13
 
18
- def _create_env
19
- Internals::Environment.new("GUARD").tap do |env|
20
- env.create_method(:strict?)
21
- end
14
+ def silence_deprecations?
15
+ gem_silence_deprecations?
22
16
  end
23
17
  end
24
18
  end
@@ -26,8 +26,11 @@ module Guard
26
26
  end
27
27
 
28
28
  def reevaluate_guardfile
29
+ # require guard only when needed, becuase
30
+ # guard's deprecations require us
31
+ require "guard"
29
32
  UI.deprecation(REEVALUATE_GUARDFILE)
30
- ::Guard::Reevaluator.new.reevaluate
33
+ ::Guard.state.reset_session { evaluate }
31
34
  end
32
35
  end
33
36
  end
@@ -2,7 +2,8 @@ require "guard/config"
2
2
  fail "Deprecations disabled (strict mode)" if Guard::Config.new.strict?
3
3
 
4
4
  require "guard/ui"
5
- require "guard/plugin_util"
5
+ require "guard/internals/session"
6
+ require "guard/internals/state"
6
7
  require "guard/guardfile/evaluator"
7
8
 
8
9
  module Guard
@@ -34,7 +35,7 @@ module Guard
34
35
 
35
36
  def guards(filter = nil)
36
37
  ::Guard::UI.deprecation(GUARDS)
37
- plugins(filter)
38
+ ::Guard.state.session.plugins.all(filter)
38
39
  end
39
40
 
40
41
  # @deprecated Use `Guard.add_plugin(name, options = {})` instead.
@@ -133,6 +134,15 @@ module Guard
133
134
  UI.deprecation(LOCK)
134
135
  end
135
136
 
137
+ LISTENER_ASSIGN = <<-EOS.gsub(/^\s*/, "")
138
+ listener= should not be used
139
+ EOS
140
+
141
+ def listener=(_)
142
+ UI.deprecation(LISTENER_ASSIGN)
143
+ ::Guard.listener
144
+ end
145
+
136
146
  EVALUATOR = <<-EOS.gsub(/^\s*/, "")
137
147
  Starting with Guard 2.8.2 this method shouldn't be used
138
148
  EOS
@@ -184,6 +194,86 @@ module Guard
184
194
  UI.deprecation(OPTIONS)
185
195
  ::Guard.state.session.options
186
196
  end
197
+
198
+ ADD_GROUP = <<-EOS.gsub(/^\s*/, "")
199
+ add_group is deprecated since 2.10.0 in favor of
200
+ Guard.state.session.groups.add
201
+ EOS
202
+
203
+ def add_group(name, options = {})
204
+ UI.deprecation(ADD_GROUP)
205
+ ::Guard.state.session.groups.add(name, options)
206
+ end
207
+
208
+ ADD_PLUGIN = <<-EOS.gsub(/^\s*/, "")
209
+ add_plugin is deprecated since 2.10.0 in favor of
210
+ Guard.state.session.plugins.add
211
+ EOS
212
+
213
+ def add_plugin(name, options = {})
214
+ UI.deprecation(ADD_PLUGIN)
215
+ ::Guard.state.session.plugins.add(name, options)
216
+ end
217
+
218
+ GROUP = <<-EOS.gsub(/^\s*/, "")
219
+ group is deprecated since 2.10.0 in favor of
220
+ Guard.state.session.group.add(filter).first
221
+ EOS
222
+
223
+ def group(filter)
224
+ UI.deprecation(GROUP)
225
+ ::Guard.state.session.groups.all(filter).first
226
+ end
227
+
228
+ PLUGIN = <<-EOS.gsub(/^\s*/, "")
229
+ plugin is deprecated since 2.10.0 in favor of
230
+ Guard.state.session.group.add(filter).first
231
+ EOS
232
+
233
+ def plugin(filter)
234
+ UI.deprecation(PLUGIN)
235
+ ::Guard.state.session.plugins.all(filter).first
236
+ end
237
+
238
+ GROUPS = <<-EOS.gsub(/^\s*/, "")
239
+ group is deprecated since 2.10.0 in favor of
240
+ Guard.state.session.groups.all(filter)
241
+ EOS
242
+
243
+ def groups(filter)
244
+ UI.deprecation(GROUPS)
245
+ ::Guard.state.session.groups.all(filter)
246
+ end
247
+
248
+ PLUGINS = <<-EOS.gsub(/^\s*/, "")
249
+ plugins is deprecated since 2.10.0 in favor of
250
+ Guard.state.session.plugins.all(filter)
251
+ EOS
252
+
253
+ def plugins(filter)
254
+ UI.deprecation(PLUGINS)
255
+ ::Guard.state.session.plugins.all(filter)
256
+ end
257
+
258
+ SCOPE = <<-EOS.gsub(/^\s*/, "")
259
+ scope is deprecated since 2.10.0 in favor of
260
+ Guard.state.scope.to_hash
261
+ EOS
262
+
263
+ def scope
264
+ UI.deprecation(SCOPE)
265
+ ::Guard.state.scope.to_hash
266
+ end
267
+
268
+ SCOPE_ASSIGN = <<-EOS.gsub(/^\s*/, "")
269
+ scope= is deprecated since 2.10.0 in favor of
270
+ Guard.state.scope.to_hash
271
+ EOS
272
+
273
+ def scope=(scope)
274
+ UI.deprecation(SCOPE_ASSIGN)
275
+ ::Guard.state.scope.from_interactor(scope)
276
+ end
187
277
  end
188
278
  end
189
279
  end
@@ -3,6 +3,7 @@ require "formatador"
3
3
 
4
4
  require "guard/ui"
5
5
  require "guard/notifier"
6
+ require "guard"
6
7
 
7
8
  require "set"
8
9
  require "ostruct"
@@ -26,6 +27,7 @@ module Guard
26
27
  # @see CLI#list
27
28
  #
28
29
  def list
30
+ # TODO: remove dependency on Guard in this whole file
29
31
  # collect metadata
30
32
  data = PluginUtil.plugin_names.sort.inject({}) do |hash, name|
31
33
  hash[name.capitalize] = Guard.state.session.plugins.all(name).any?
@@ -1,12 +1,11 @@
1
1
  require "guard/config"
2
+ require "guard/deprecated/evaluator" unless Guard::Config.new.strict?
2
3
 
3
4
  require "guard/options"
4
5
  require "guard/plugin"
5
6
 
6
7
  require "guard/dsl"
7
8
 
8
- require "guard/deprecated/evaluator" unless Guard::Config.new.strict?
9
-
10
9
  module Guard
11
10
  module Guardfile
12
11
  # This class is responsible for evaluating the Guardfile. It delegates to
@@ -1,5 +1,3 @@
1
- require "guard/ui"
2
-
3
1
  module Guard
4
2
  class Interactor
5
3
  # Initializes the interactor. This configures
@@ -55,33 +53,6 @@ module Guard
55
53
 
56
54
  # TODO: handle switching interactors during runtime?
57
55
  attr_writer :enabled
58
-
59
- # Converts and validates a plain text scope
60
- # to a valid plugin or group scope.
61
- #
62
- # @param [Array<String>] entries the text scope
63
- # @return [Hash, Array<String>] the plugin or group scope, the unknown
64
- # entries
65
- #
66
- # TODO: call this from within action, not within interactor command
67
- def convert_scope(entries)
68
- scopes = { plugins: [], groups: [] }
69
- unknown = []
70
-
71
- session = Guard.state.session
72
-
73
- entries.each do |entry|
74
- if plugin = session.plugins.all(entry).first
75
- scopes[:plugins] << plugin
76
- elsif group = session.groups.all(entry).first
77
- scopes[:groups] << group
78
- else
79
- unknown << entry
80
- end
81
- end
82
-
83
- [scopes, unknown]
84
- end
85
56
  end
86
57
 
87
58
  private
@@ -1,3 +1,5 @@
1
+ require "guard/plugin_util"
2
+ require "guard/group"
1
3
  require "guard/plugin"
2
4
 
3
5
  module Guard
@@ -1,3 +1,5 @@
1
+ require "guard"
2
+
1
3
  module Guard
2
4
  # @private api
3
5
  module Internals
@@ -82,10 +84,12 @@ module Guard
82
84
  !source.empty?
83
85
  end
84
86
 
87
+ # TODO: not tested when groups/plugins given don't exist
88
+
85
89
  # TODO: should already be instantiated
86
90
  Array(items).map do |name|
87
91
  (type == :group ? _groups : _plugins).all(name).first
88
- end
92
+ end.compact
89
93
  end
90
94
 
91
95
  def _instantiate(meth, obj)
@@ -8,9 +8,6 @@ module Guard
8
8
  module Internals
9
9
  # TODO: split into a commandline class and session (plugins, groups)
10
10
  # TODO: swap session and metadata
11
- # This class contains variables set during
12
- # evaluation of the guardfile (and are reset
13
- # before reevaluation)
14
11
  class Session
15
12
  attr_reader :options
16
13
  attr_reader :plugins
@@ -55,8 +52,8 @@ module Guard
55
52
  def initialize(new_options)
56
53
  @options = Options.new(new_options, DEFAULT_OPTIONS)
57
54
 
58
- @plugins = Internals::Plugins.new
59
- @groups = Internals::Groups.new
55
+ @plugins = Plugins.new
56
+ @groups = Groups.new
60
57
 
61
58
  @cmdline_groups = @options[:group]
62
59
  @cmdline_plugins = @options[:plugin]
@@ -83,9 +80,13 @@ module Guard
83
80
  # TODO: create a EvaluatorResult class?
84
81
  attr_reader :guardfile_group_scope
85
82
  attr_reader :guardfile_plugin_scope
86
- attr_accessor :guardfile_ignore
87
83
  attr_accessor :guardfile_ignore_bang
88
84
 
85
+ attr_reader :guardfile_ignore
86
+ def guardfile_ignore=(ignores)
87
+ @guardfile_ignore += Array(ignores).flatten
88
+ end
89
+
89
90
  def clearing(on)
90
91
  @clear = on
91
92
  end
@@ -140,6 +141,24 @@ module Guard
140
141
  def interactor_name
141
142
  @interactor_name
142
143
  end
144
+
145
+ # TODO: call this from within action, not within interactor command
146
+ def convert_scope(entries)
147
+ scopes = { plugins: [], groups: [] }
148
+ unknown = []
149
+
150
+ entries.each do |entry|
151
+ if plugin = plugins.all(entry).first
152
+ scopes[:plugins] << plugin
153
+ elsif group = groups.all(entry).first
154
+ scopes[:groups] << group
155
+ else
156
+ unknown << entry
157
+ end
158
+ end
159
+
160
+ [scopes, unknown]
161
+ end
143
162
  end
144
163
  end
145
164
  end
@@ -3,16 +3,15 @@ require "guard/group"
3
3
  require "guard/plugin_util"
4
4
  require "guard/internals/session"
5
5
  require "guard/internals/scope"
6
+ require "guard/runner"
6
7
 
7
8
  module Guard
8
9
  module Internals
9
10
  class State
10
11
  # Minimal setup for non-interactive commands (list, init, show, etc.)
11
12
  def initialize(cmdline_opts)
12
- # NOTE: this is reset during reevaluation
13
13
  @session = Session.new(cmdline_opts)
14
14
 
15
- # NOTE: this should persist across reevaluate() calls
16
15
  @scope = Scope.new
17
16
 
18
17
  # NOTE: must be set before anything calls Guard::UI.debug
@@ -23,10 +22,16 @@ module Guard
23
22
  attr_reader :session
24
23
 
25
24
  # @private api
26
- # used to clear instance variables during reevaluation
27
- def reset_session
25
+ # TODO: REMOVE!
26
+ def reset_session(&block)
27
+ Runner.new.run(:stop)
28
+ Notifier.disconnect
28
29
  options = @session.options.dup
29
30
  @session = Session.new(options)
31
+ block.call
32
+ Runner.new.run(:start)
33
+ ensure
34
+ Notifier.connect(session.notify_options)
30
35
  end
31
36
  end
32
37
  end
@@ -1,8 +1,8 @@
1
1
  require "yaml"
2
2
  require "rbconfig"
3
3
  require "pathname"
4
+ require "nenv"
4
5
 
5
- require_relative "internals/environment"
6
6
  require_relative "notifier/detected"
7
7
 
8
8
  require_relative "ui"
@@ -71,6 +71,14 @@ module Guard
71
71
  { file: FileNotifier }
72
72
  ]
73
73
 
74
+ Env = Nenv::Builder.build do
75
+ create_method(:notify?) { |data| data != "false" }
76
+ create_method(:notify_pid) { |data| data && Integer(data) }
77
+ create_method(:notify_pid=)
78
+ create_method(:notify_active?)
79
+ create_method(:notify_active=)
80
+ end
81
+
74
82
  class NotServer < RuntimeError
75
83
  end
76
84
 
@@ -216,17 +224,7 @@ module Guard
216
224
  private
217
225
 
218
226
  def _env
219
- (@environment ||= _create_env)
220
- end
221
-
222
- def _create_env
223
- Internals::Environment.new("GUARD").tap do |env|
224
- env.create_method(:notify?) { |data| data != "false" }
225
- env.create_method(:notify_pid) { |data| data && Integer(data) }
226
- env.create_method(:notify_pid=)
227
- env.create_method(:notify_active?)
228
- env.create_method(:notify_active=)
229
- end
227
+ @environment ||= Env.new("guard")
230
228
  end
231
229
 
232
230
  def _check_server!
@@ -1,4 +1,4 @@
1
- require "guard/internals/environment"
1
+ require "nenv"
2
2
 
3
3
  require_relative "../notifiers/emacs"
4
4
  require_relative "../notifiers/file_notifier"
@@ -13,6 +13,13 @@ require_relative "../notifiers/tmux"
13
13
 
14
14
  module Guard
15
15
  module Notifier
16
+ # @private api
17
+
18
+ YamlEnvStorage = Nenv::Builder.build do
19
+ create_method(:notifiers=) { |data| YAML::dump(data) }
20
+ create_method(:notifiers) { |data| data ? YAML::load(data) : [] }
21
+ end
22
+
16
23
  # @private api
17
24
  class Detected
18
25
  NO_SUPPORTED_NOTIFIERS = "Guard could not detect any of the supported" +
@@ -23,10 +30,7 @@ module Guard
23
30
 
24
31
  def initialize(supported)
25
32
  @supported = supported
26
- @environment = Internals::Environment.new("GUARD").tap do |env|
27
- env.create_method(:notifiers=) { |data| YAML::dump(data) }
28
- env.create_method(:notifiers) { |data| data ? YAML::load(data) : [] }
29
- end
33
+ @environment = YamlEnvStorage.new("guard")
30
34
  end
31
35
 
32
36
  def reset