guard 2.7.0 → 2.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f713c5e30ef7f2814a804f5fafdb58979caa6619
4
- data.tar.gz: ce94c3678722ee2d4d6ddfca527d5d598fffa069
3
+ metadata.gz: 1c86565038c0d17ebb30f6cc008bd4daa3ec3146
4
+ data.tar.gz: 7de5a07cdad205ab62306ecab6f044222406dd1e
5
5
  SHA512:
6
- metadata.gz: 3fdcb3cad5b86d6b36d570c4c534742ad9613e164c660c6de608a38771afd5f776a6cbc2e2a81bbc43330058175a9ee73c86a8b76766cdb6918df3b60f434cc2
7
- data.tar.gz: 9ff385cce046e434c8a2b577915e58453793dce6b6aa08fccc20bf293421ba862872d7df0c80e37737c5e7bceed972ea4e26c87c11c2f2a80086c6c95a01fc8c
6
+ metadata.gz: 72ae5a7b063bb4fa07fcfe0dc7b7673dd97a1d3099d4dcf846b7cf3c62040f9a4850a32168df6545eb80a7e62bfdc0f20bc1967239c376a6559a96e95050ebc2
7
+ data.tar.gz: 0e182edbd7934d9524c6261c2db55b1d3cd9b4c9ed8aea9dd66ece1cffd9534f6226abd9b3e705caaea1543891bd36f2e783714435a3577a94824023f6617808
data/bin/guard CHANGED
@@ -1,6 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "guard"
4
- require "guard/cli"
5
4
 
6
- Guard::CLI.start
5
+ begin
6
+ require "guard/aruba_adapter"
7
+ rescue LoadError => e
8
+ abort "#{e.inspect} - perhaps you need to run using `bundle exec`?"
9
+ end
10
+
11
+ Guard::ArubaAdapter.new(ARGV.dup).execute!
data/lib/guard.rb CHANGED
@@ -20,22 +20,25 @@ require "guard/reevaluator"
20
20
  # Also Guard plugins should use this namespace.
21
21
  #
22
22
  module Guard
23
- WINDOWS = RbConfig::CONFIG["host_os"] =~ /(?:msdos|mswin|djgpp|mingw)/
24
- DEV_NULL = WINDOWS ? "NUL" : "/dev/null"
23
+ DEV_NULL = Gem.win_platform? ? "NUL" : "/dev/null"
25
24
 
26
25
  extend Commander
27
26
  extend DeprecatedMethods
28
27
  extend Setuper
29
28
 
30
29
  class << self
31
- attr_accessor :runner, :listener, :lock, :running
32
-
33
30
  # Called by Pry scope command
34
- attr_reader :scope
35
31
 
36
32
  def scope=(new_scope)
37
33
  @scope = new_scope
34
+ @scope.dup.freeze
35
+ end
36
+
37
+ def scope
38
+ fail "::Guard.setup() not called" if @scope.nil?
39
+ @scope.dup.freeze
38
40
  end
41
+ attr_reader :runner, :listener
39
42
 
40
43
  # Smart accessor for retrieving specific plugins at once.
41
44
  #
@@ -137,6 +140,8 @@ module Guard
137
140
  @groups.select { |group| group.name == filter.to_sym }
138
141
  when Regexp
139
142
  @groups.select { |group| group.name.to_s =~ filter }
143
+ else
144
+ fail "Invalid filter: #{filter.inspect}"
140
145
  end
141
146
  end
142
147
 
@@ -176,6 +181,12 @@ module Guard
176
181
  instance
177
182
  end
178
183
 
184
+ # Used by runner to remove a failed plugin
185
+ def remove_plugin(plugin)
186
+ # TODO: coverage/aruba
187
+ @plugins.delete(plugin)
188
+ end
189
+
179
190
  # Add a Guard plugin group.
180
191
  #
181
192
  # @param [String] name the group name
data/lib/guard.rb.orig ADDED
@@ -0,0 +1,210 @@
1
+ require "rbconfig"
2
+
3
+ require "guard/commander"
4
+ require "guard/deprecated_methods"
5
+ require "guard/deprecator"
6
+ require "guard/dsl"
7
+ require "guard/group"
8
+ require "guard/guardfile"
9
+ require "guard/interactor"
10
+ require "guard/notifier"
11
+ require "guard/plugin_util"
12
+ require "guard/runner"
13
+ require "guard/setuper"
14
+ require "guard/sheller"
15
+ require "guard/ui"
16
+ require "guard/watcher"
17
+ require "guard/reevaluator"
18
+
19
+ # Guard is the main module for all Guard related modules and classes.
20
+ # Also Guard plugins should use this namespace.
21
+ #
22
+ module Guard
23
+ DEV_NULL = Gem.win_platform? ? "NUL" : "/dev/null"
24
+
25
+ extend Commander
26
+ extend DeprecatedMethods
27
+ extend Setuper
28
+
29
+ class << self
30
+ # Called by Pry scope command
31
+
32
+ def scope=(new_scope)
33
+ @scope = new_scope
34
+ @scope.dup.freeze
35
+ end
36
+
37
+ def scope
38
+ fail "::Guard.setup() not called" if @scope.nil?
39
+ @scope.dup.freeze
40
+ end
41
+ attr_reader :runner, :listener
42
+
43
+ # Smart accessor for retrieving specific plugins at once.
44
+ #
45
+ # @see Guard.plugin
46
+ # @see Guard.group
47
+ # @see Guard.groups
48
+ #
49
+ # @example Filter plugins by String or Symbol
50
+ # Guard.plugins('rspec')
51
+ # Guard.plugins(:rspec)
52
+ #
53
+ # @example Filter plugins by Regexp
54
+ # Guard.plugins(/rsp.+/)
55
+ #
56
+ # @example Filter plugins by Hash
57
+ # Guard.plugins(name: 'rspec', group: 'backend')
58
+ #
59
+ # @param [String, Symbol, Regexp, Hash] filter the filter to apply to the
60
+ # plugins
61
+ # @return [Plugin, Array<Plugin>] the filtered plugin(s)
62
+ #
63
+ def plugins(filter = nil)
64
+ @plugins ||= []
65
+
66
+ return @plugins if filter.nil?
67
+
68
+ filtered_plugins = case filter
69
+ when String, Symbol
70
+ @plugins.select do |plugin|
71
+ plugin.name == filter.to_s.downcase.gsub("-", "")
72
+ end
73
+ when Regexp
74
+ @plugins.select do |plugin|
75
+ plugin.name =~ filter
76
+ end
77
+ when Hash
78
+ @plugins.select do |plugin|
79
+ filter.all? do |k, v|
80
+ case k
81
+ when :name
82
+ plugin.name == v.to_s.downcase.gsub("-", "")
83
+ when :group
84
+ plugin.group.name == v.to_sym
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ filtered_plugins
91
+ end
92
+
93
+ # Smart accessor for retrieving a specific plugin.
94
+ #
95
+ # @see Guard.plugins
96
+ # @see Guard.group
97
+ # @see Guard.groups
98
+ #
99
+ # @example Find a plugin by String or Symbol
100
+ # Guard.plugin('rspec')
101
+ # Guard.plugin(:rspec)
102
+ #
103
+ # @example Find a plugin by Regexp
104
+ # Guard.plugin(/rsp.+/)
105
+ #
106
+ # @example Find a plugin by Hash
107
+ # Guard.plugin(name: 'rspec', group: 'backend')
108
+ #
109
+ # @param [String, Symbol, Regexp, Hash] filter the filter for finding the
110
+ # plugin the Guard plugin
111
+ # @return [Plugin, nil] the plugin found, nil otherwise
112
+ #
113
+ def plugin(filter)
114
+ plugins(filter).first
115
+ end
116
+
117
+ # Smart accessor for retrieving specific groups at once.
118
+ #
119
+ # @see Guard.plugin
120
+ # @see Guard.plugins
121
+ # @see Guard.group
122
+ #
123
+ # @example Filter groups by String or Symbol
124
+ # Guard.groups('backend')
125
+ # Guard.groups(:backend)
126
+ #
127
+ # @example Filter groups by Regexp
128
+ # Guard.groups(/(back|front)end/)
129
+ #
130
+ # @param [String, Symbol, Regexp] filter the filter to apply to the Groups
131
+ # @return [Array<Group>] the filtered group(s)
132
+ #
133
+ def groups(filter = nil)
134
+ @groups ||= []
135
+
136
+ return @groups if filter.nil?
137
+
138
+ case filter
139
+ when String, Symbol
140
+ @groups.select { |group| group.name == filter.to_sym }
141
+ when Regexp
142
+ @groups.select { |group| group.name.to_s =~ filter }
143
+ else
144
+ fail "Invalid filter: #{filter.inspect}"
145
+ end
146
+ end
147
+
148
+ # Smart accessor for retrieving a specific group.
149
+ #
150
+ # @see Guard.plugin
151
+ # @see Guard.plugins
152
+ # @see Guard.groups
153
+ #
154
+ # @example Find a group by String or Symbol
155
+ # Guard.group('backend')
156
+ # Guard.group(:backend)
157
+ #
158
+ # @example Find a group by Regexp
159
+ # Guard.group(/(back|front)end/)
160
+ #
161
+ # @param [String, Symbol, Regexp] filter the filter for finding the group
162
+ # @return [Group] the group found, nil otherwise
163
+ #
164
+ def group(filter)
165
+ groups(filter).first
166
+ end
167
+
168
+ # Add a Guard plugin to use.
169
+ #
170
+ # @param [String] name the Guard name
171
+ # @param [Hash] options the plugin options (see Plugin documentation)
172
+ # @option options [String] group the group to which the plugin belongs
173
+ # @option options [Array<Watcher>] watchers the list of declared watchers
174
+ # @option options [Array<Hash>] callbacks the list of callbacks
175
+ # @return [Plugin] the added Guard plugin
176
+ # @see Plugin
177
+ #
178
+ def add_plugin(name, options = {})
179
+ instance = ::Guard::PluginUtil.new(name).initialize_plugin(options)
180
+ @plugins << instance
181
+ instance
182
+ end
183
+
184
+ # Used by runner to remove a failed plugin
185
+ def remove_plugin(plugin)
186
+ # TODO: coverage/aruba
187
+ @plugins.delete(plugin)
188
+ end
189
+
190
+ # Add a Guard plugin group.
191
+ #
192
+ # @param [String] name the group name
193
+ # @option options [Boolean] halt_on_fail if a task execution
194
+ # should be halted for all Guard plugins in this group if
195
+ # one Guard throws `:task_has_failed`
196
+ # @return [Group] the group added (or retrieved from the `@groups`
197
+ # variable if already present)
198
+ #
199
+ # @see Group
200
+ #
201
+ def add_group(name, options = {})
202
+ unless (group = group(name))
203
+ group = ::Guard::Group.new(name, options)
204
+ @groups << group
205
+ end
206
+
207
+ group
208
+ end
209
+ end
210
+ end
@@ -0,0 +1,59 @@
1
+ require "guard/cli"
2
+
3
+ module Guard
4
+ class ArubaAdapter
5
+ def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR,
6
+ kernel = Kernel)
7
+ @argv = argv
8
+ @stdin = stdin
9
+ @stdout = stdout
10
+ @stderr = stderr
11
+ @kernel = kernel
12
+
13
+ if ENV["INSIDE_ARUBA_TEST"] == "1"
14
+ ::Guard::UI.options = ::Guard::UI.options.merge(flush_seconds: 0)
15
+ end
16
+ end
17
+
18
+ def execute!
19
+ exit_code = execute
20
+ # Proxy our exit code back to the injected kernel.
21
+ @kernel.exit(exit_code)
22
+ end
23
+
24
+ def execute
25
+ # Thor accesses these streams directly rather than letting
26
+ # them be injected, so we replace them...
27
+ $stderr = @stderr
28
+ $stdin = @stdin
29
+ $stdout = @stdout
30
+
31
+ # Run our normal Thor app the way we know and love.
32
+ ::Guard::CLI.start(@argv)
33
+
34
+ # Thor::Base#start does not have a return value, assume
35
+ # success if no exception is raised.
36
+ 0
37
+ rescue StandardError => e
38
+ # The ruby interpreter would pipe this to STDERR and exit 1 in the case
39
+ # of an unhandled exception
40
+ b = e.backtrace
41
+ b.unshift("#{b.shift}: #{e.message} (#{e.class})")
42
+ @stderr.puts(b.map { |s| "\tfrom #{s}" }.join("\n"))
43
+ 1
44
+ rescue SystemExit => e
45
+ e.status
46
+ ensure
47
+ # flush the logger so the output doesn't appear in next CLI invocation
48
+ ::Guard.listener.stop if ::Guard.listener
49
+ ::Guard::UI.logger.flush
50
+ ::Guard::UI.logger.close
51
+ ::Guard::UI.reset_logger
52
+
53
+ # ...then we put them back.
54
+ $stderr = STDERR
55
+ $stdin = STDIN
56
+ $stdout = STDOUT
57
+ end
58
+ end
59
+ end
data/lib/guard/cli.rb CHANGED
@@ -141,7 +141,7 @@ module Guard
141
141
  # @see Guard::VERSION
142
142
  #
143
143
  def version
144
- STDOUT.puts "Guard version #{ ::Guard::VERSION }"
144
+ $stdout.puts "Guard version #{ ::Guard::VERSION }"
145
145
  end
146
146
 
147
147
  desc "init [GUARDS]", "Generates a Guardfile at the current directory"\
@@ -24,7 +24,9 @@ module Guard
24
24
  ::Guard::UI.debug "Guard starts all plugins"
25
25
  runner.run(:start)
26
26
  listener.start
27
- ::Guard::UI.info "Guard is now watching at '#{ @watchdirs.join "', '" }'"
27
+
28
+ watched = ::Guard.watchdirs.join("', '")
29
+ ::Guard::UI.info "Guard is now watching at '#{ watched }'"
28
30
 
29
31
  _interactor_loop
30
32
  end
@@ -27,7 +27,7 @@ module Guard
27
27
  return
28
28
  end
29
29
 
30
- ::Guard.scope = scope
30
+ ::Guard.setup_scope(scope)
31
31
  end
32
32
  end
33
33
  end
@@ -51,5 +51,21 @@ module Guard
51
51
  UI.deprecation(Deprecator::GUARD_GEM_NAMES_DEPRECATION)
52
52
  PluginUtil.plugin_names
53
53
  end
54
+
55
+ def running
56
+ UI.deprecation(Deprecator::GUARD_RUNNING_DEPRECATION)
57
+ nil
58
+ end
59
+
60
+ def lock
61
+ UI.deprecation(Deprecator::GUARD_LOCK_DEPRECATION)
62
+ end
63
+
64
+ def evaluator
65
+ UI.deprecation(Deprecator::GUARD_EVALUATOR_DEPRECATION)
66
+ # TODO: this will be changed to the following when scope is reworked
67
+ # ::Guard.session.evaluator
68
+ ::Guard.instance_variable_get(:@evaluator)
69
+ end
54
70
  end
55
71
  end
@@ -118,5 +118,20 @@ module Guard
118
118
 
119
119
  #{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#changes-in-guardguard"}
120
120
  EOS
121
+
122
+ GUARD_RUNNING_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
123
+ Starting with Guard 2.7.1 it was discovered that Guard.running was never
124
+ initialized or used internally.
125
+ EOS
126
+
127
+ GUARD_LOCK_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
128
+ Starting with Guard 2.7.1 it was discovered that this accessor was never
129
+ initialized or used internally.
130
+ EOS
131
+
132
+ GUARD_EVALUATOR_DEPRECATION = <<-EOS.gsub(/^\s*/, "")
133
+ Starting with Guard 2.7.1 ::Guard.session.evaluator should be used
134
+ instead.
135
+ EOS
121
136
  end
122
137
  end
@@ -35,8 +35,6 @@ module Guard
35
35
  # @see CLI#list
36
36
  #
37
37
  def list
38
- _evaluate_guardfile
39
-
40
38
  names = ::Guard::PluginUtil.plugin_names.sort.uniq
41
39
  final_rows = names.inject([]) do |rows, name|
42
40
  rows << {
@@ -50,8 +50,8 @@ module Guard
50
50
  #
51
51
  def evaluate_guardfile
52
52
  _fetch_guardfile_contents
53
- ::Guard.add_builtin_plugins(guardfile_path)
54
53
  _instance_eval_guardfile(guardfile_contents)
54
+ ::Guard.add_builtin_plugins(guardfile_path)
55
55
  end
56
56
 
57
57
  # Re-evaluates the `Guardfile` to update
@@ -221,7 +221,7 @@ module Guard
221
221
  def _after_reevaluate_guardfile
222
222
  ::Guard::Notifier.turn_on if ::Guard::Notifier.enabled?
223
223
 
224
- if !::Guard.send(:_non_builtin_plugins?)
224
+ if !::Guard.send(:_pluginless_guardfile?)
225
225
  ::Guard::Notifier.notify(
226
226
  "No plugins found in Guardfile, please add at least one.",
227
227
  title: "Guard re-evaluate",