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.
@@ -0,0 +1,11 @@
1
+ module Guard
2
+ class Terminal
3
+ class << self
4
+ def clear
5
+ cmd = Gem.win_platform? ? "cls" : "clear;"
6
+ exit_code, _, stderr = ::Guard::Sheller.system(cmd)
7
+ fail Errno::ENOENT, stderr unless exit_code == 0
8
+ end
9
+ end
10
+ end
11
+ end
File without changes
data/lib/guard/ui.rb CHANGED
@@ -3,6 +3,8 @@ require "lumberjack"
3
3
  require "guard/options"
4
4
  require "guard/ui/colors"
5
5
 
6
+ require "guard/terminal"
7
+
6
8
  module Guard
7
9
  # The UI class helps to format messages for the user. Everything that is
8
10
  # logged through this class is considered either as an error message or a
@@ -25,6 +27,14 @@ module Guard
25
27
  end
26
28
  end
27
29
 
30
+ # Since logger is global, for Aruba in-process to properly
31
+ # separate output between calls, we need to reset
32
+ #
33
+ # We don't use logger=() since it's expected to be a Lumberjack instance
34
+ def reset_logger
35
+ @logger = nil
36
+ end
37
+
28
38
  # Get the logger options
29
39
  #
30
40
  # @return [Hash] the logger options
@@ -109,9 +119,18 @@ module Guard
109
119
  # Clear the output if clearable.
110
120
  #
111
121
  def clear(options = {})
122
+ fail "UI not set up!" if @clearable.nil?
112
123
  return unless ::Guard.options[:clear] && (@clearable || options[:force])
113
124
  @clearable = false
114
- ::Guard::Sheller.run("clear;")
125
+ ::Guard::Terminal.clear
126
+ rescue Errno::ENOENT => e
127
+ warning("Failed to clear the screen: #{e.inspect}")
128
+ end
129
+
130
+ # TODO: arguments: UI uses Guard::options anyway
131
+ def setup(_options)
132
+ @clearable = false
133
+ clear(force: true)
115
134
  end
116
135
 
117
136
  # Allow the screen to be cleared again.
@@ -206,7 +225,7 @@ module Guard
206
225
  @color_enabled = nil unless @color_enabled_initialized
207
226
  @color_enabled_initialized = true
208
227
  if @color_enabled.nil?
209
- if RbConfig::CONFIG["target_os"] =~ /mswin|mingw/i
228
+ if Gem.win_platform?
210
229
  if ENV["ANSICON"]
211
230
  @color_enabled = true
212
231
  else
data/lib/guard/ui.rb.orig CHANGED
@@ -25,6 +25,14 @@ module Guard
25
25
  end
26
26
  end
27
27
 
28
+ # Since logger is global, for Aruba in-process to properly
29
+ # separate output between calls, we need to reset
30
+ #
31
+ # We don't use logger=() since it's expected to be a Lumberjack instance
32
+ def reset_logger
33
+ @logger = nil
34
+ end
35
+
28
36
  # Get the logger options
29
37
  #
30
38
  # @return [Hash] the logger options
@@ -85,6 +93,8 @@ module Guard
85
93
  # @option options [String] plugin manually define the calling plugin
86
94
  #
87
95
  def deprecation(message, options = {})
96
+ msg = "neither ::Guard.setup nor ::Guard.reset_options was called"
97
+ fail msg if ::Guard.options.nil?
88
98
  warning(message, options) if ::Guard.options[:show_deprecations]
89
99
  end
90
100
 
@@ -204,7 +214,7 @@ module Guard
204
214
  @color_enabled = nil unless @color_enabled_initialized
205
215
  @color_enabled_initialized = true
206
216
  if @color_enabled.nil?
207
- if RbConfig::CONFIG["target_os"] =~ /mswin|mingw/i
217
+ if Gem.win_platform?
208
218
  if ENV["ANSICON"]
209
219
  @color_enabled = true
210
220
  else
data/lib/guard/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Guard
2
- VERSION = "2.7.0"
2
+ VERSION = "2.7.1"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module Guard
2
- VERSION = "2.6.1"
2
+ VERSION = "2.7.0"
3
3
  end
@@ -0,0 +1,119 @@
1
+ require "guard/ui"
2
+
3
+ module Guard
4
+ # The watcher defines a RegExp that will be matched against file system
5
+ # modifications.
6
+ # When a watcher matches a change, an optional action block is executed to
7
+ # enable processing the file system change result.
8
+ #
9
+ class Watcher
10
+ attr_accessor :pattern, :action
11
+
12
+ # Initializes a file watcher.
13
+ #
14
+ # @param [String, Regexp] pattern the pattern to be watched by the Guard
15
+ # plugin
16
+ # @param [Block] action the action to execute before passing the result to
17
+ # the Guard plugin
18
+ #
19
+ def initialize(pattern, action = nil)
20
+ @pattern, @action = pattern, action
21
+ @@warning_printed ||= false
22
+
23
+ # deprecation warning
24
+ regexp = /(^(\^))|(>?(\\\.)|(\.\*))|(\(.*\))|(\[.*\])|(\$$)/
25
+ return unless @pattern.is_a?(String) && @pattern =~ regexp
26
+
27
+ unless @@warning_printed
28
+ ::Guard::UI.info "*" * 20 + "\nDEPRECATION WARNING!\n" + "*" * 20
29
+ ::Guard::UI.info <<-MSG
30
+ You have a string in your Guardfile watch patterns that seem to
31
+ represent a Regexp.
32
+
33
+ Guard matches String with == and Regexp with Regexp#match.
34
+
35
+ You should either use plain String (without Regexp special
36
+ characters) or real Regexp.
37
+ MSG
38
+ @@warning_printed = true
39
+ end
40
+
41
+ new_regexp = Regexp.new(@pattern).inspect
42
+ ::Guard::UI.info "\"#{@pattern}\" has been converted to #{ new_regexp }\n"
43
+ @pattern = Regexp.new(@pattern)
44
+ end
45
+
46
+ # Finds the files that matches a Guard plugin.
47
+ #
48
+ # @param [Guard::Plugin] guard the Guard plugin which watchers are used
49
+ # @param [Array<String>] files the changed files
50
+ # @return [Array<Object>] the matched watcher response
51
+ #
52
+ def self.match_files(guard, files)
53
+ return [] if files.empty?
54
+
55
+ files.inject([]) do |paths, file|
56
+ guard.watchers.each do |watcher|
57
+ matches = watcher.match(file)
58
+ next unless matches
59
+
60
+ if watcher.action
61
+ result = watcher.call_action(matches)
62
+ if guard.options[:any_return]
63
+ paths << result
64
+ elsif result.respond_to?(:empty?) && !result.empty?
65
+ paths << Array(result)
66
+ else
67
+ next
68
+ end
69
+ else
70
+ paths << matches[0]
71
+ end
72
+
73
+ break if guard.options[:first_match]
74
+ end
75
+
76
+ guard.options[:any_return] ? paths : paths.flatten.map(&:to_s)
77
+ end
78
+ end
79
+
80
+ # Tests if any of the files is the Guardfile.
81
+ #
82
+ # @param [Array<String>] files the files to test
83
+ # @return [Boolean] whether one of these files is the Guardfile
84
+ #
85
+ def self.match_guardfile?(files)
86
+ path = ::Guard.evaluator.guardfile_path
87
+ files.any? { |file| File.expand_path(file) == path }
88
+ end
89
+
90
+ # Test the watchers pattern against a file.
91
+ #
92
+ # @param [String] file the file to test
93
+ # @return [Array<String>] an array of matches (or containing a single path
94
+ # if the pattern is a string)
95
+ #
96
+ def match(string_or_pathname)
97
+ # TODO: use only match() - and show fnmatch example
98
+ file = string_or_pathname.to_s
99
+ return (file == @pattern ? [file] : nil) unless @pattern.is_a?(Regexp)
100
+ return unless (m = @pattern.match(file))
101
+ m = m.to_a
102
+ m[0] = file
103
+ m
104
+ end
105
+
106
+ # Executes a watcher action.
107
+ #
108
+ # @param [String, MatchData] matches the matched path or the match from the
109
+ # Regex
110
+ # @return [String] the final paths
111
+ #
112
+ def call_action(matches)
113
+ @action.arity > 0 ? @action.call(matches) : @action.call
114
+ rescue => ex
115
+ ::Guard::UI.error "Problem with watch action!\n#{ ex.message }"
116
+ ::Guard::UI.error ex.backtrace.join("\n")
117
+ end
118
+ end
119
+ 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.7.0
4
+ version: 2.7.1
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-10-27 00:00:00.000000000 Z
11
+ date: 2014-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -98,8 +98,9 @@ files:
98
98
  - images/pending.png
99
99
  - images/success.png
100
100
  - lib/guard.rb
101
+ - lib/guard.rb.orig
102
+ - lib/guard/aruba_adapter.rb
101
103
  - lib/guard/cli.rb
102
- - lib/guard/cli.rb.orig
103
104
  - lib/guard/commander.rb
104
105
  - lib/guard/commands/all.rb
105
106
  - lib/guard/commands/change.rb
@@ -112,23 +113,21 @@ files:
112
113
  - lib/guard/deprecator.rb
113
114
  - lib/guard/dsl.rb
114
115
  - lib/guard/dsl_describer.rb
115
- - lib/guard/dsl_describer.rb.orig
116
116
  - lib/guard/group.rb
117
117
  - lib/guard/guard.rb
118
- - lib/guard/guard.rb.orig
119
118
  - lib/guard/guardfile.rb
120
119
  - lib/guard/guardfile/evaluator.rb
121
- - lib/guard/guardfile/evaluator.rb.orig
122
120
  - lib/guard/guardfile/generator.rb
123
121
  - lib/guard/interactor.rb
124
122
  - lib/guard/interactor.rb.orig
125
123
  - lib/guard/jobs/base.rb
126
124
  - lib/guard/jobs/pry_wrapper.rb
127
- - lib/guard/jobs/pry_wrapper.rb.orig
128
125
  - lib/guard/jobs/sleep.rb
126
+ - lib/guard/jobs/stdin.rb.orig
129
127
  - lib/guard/notifier.rb
130
128
  - lib/guard/notifiers/base.rb
131
129
  - lib/guard/notifiers/emacs.rb
130
+ - lib/guard/notifiers/emacs.rb.orig
132
131
  - lib/guard/notifiers/file_notifier.rb
133
132
  - lib/guard/notifiers/gntp.rb
134
133
  - lib/guard/notifiers/growl.rb
@@ -143,22 +142,24 @@ files:
143
142
  - lib/guard/plugin/base.rb
144
143
  - lib/guard/plugin/hooker.rb
145
144
  - lib/guard/plugin_util.rb
146
- - lib/guard/plugin_util.rb.orig
147
145
  - lib/guard/rake_task.rb
148
146
  - lib/guard/reevaluator.rb
149
147
  - lib/guard/runner.rb
150
- - lib/guard/runner.rb.orig
151
148
  - lib/guard/setuper.rb
152
149
  - lib/guard/setuper.rb.orig
153
150
  - lib/guard/sheller.rb
151
+ - lib/guard/sheller.rb.orig
154
152
  - lib/guard/tags
155
153
  - lib/guard/templates/Guardfile
154
+ - lib/guard/terminal.rb
155
+ - lib/guard/terminal.rb.orig
156
156
  - lib/guard/ui.rb
157
157
  - lib/guard/ui.rb.orig
158
158
  - lib/guard/ui/colors.rb
159
159
  - lib/guard/version.rb
160
160
  - lib/guard/version.rb.orig
161
161
  - lib/guard/watcher.rb
162
+ - lib/guard/watcher.rb.orig
162
163
  - man/guard.1
163
164
  - man/guard.1.html
164
165
  homepage: http://guardgem.org
@@ -1,215 +0,0 @@
1
- require "thor"
2
-
3
- require "guard"
4
- require "guard/version"
5
- require "guard/dsl_describer"
6
- require "guard/guardfile"
7
-
8
- module Guard
9
- # Facade for the Guard command line interface managed by
10
- # [Thor](https://github.com/wycats/thor).
11
- #
12
- # This is the main interface to Guard that is called by the Guard binary
13
- # `bin/guard`. Do not put any logic in here, create a class and delegate
14
- # instead.
15
- #
16
- class CLI < Thor
17
- default_task :start
18
-
19
- desc "start", "Starts Guard"
20
-
21
- method_option :clear,
22
- type: :boolean,
23
- default: false,
24
- aliases: "-c",
25
- banner: "Auto clear shell before each action"
26
-
27
- method_option :notify,
28
- type: :boolean,
29
- default: true,
30
- aliases: "-n",
31
- banner: "Notifications feature"
32
-
33
- method_option :debug,
34
- type: :boolean,
35
- default: false,
36
- aliases: "-d",
37
- banner: "Show debug information"
38
-
39
- method_option :group,
40
- type: :array,
41
- default: [],
42
- aliases: "-g",
43
- banner: "Run only the passed groups"
44
-
45
- method_option :plugin,
46
- type: :array,
47
- default: [],
48
- aliases: "-P",
49
- banner: "Run only the passed plugins"
50
-
51
- method_option :watchdir,
52
- type: :array,
53
- aliases: "-w",
54
- banner: "Specify the directories to watch"
55
-
56
- method_option :guardfile,
57
- type: :string,
58
- aliases: "-G",
59
- banner: "Specify a Guardfile"
60
-
61
- method_option :no_interactions,
62
- type: :boolean,
63
- default: false,
64
- aliases: "-i",
65
- banner: "Turn off completely any Guard terminal interactions"
66
-
67
- method_option :no_bundler_warning,
68
- type: :boolean,
69
- default: false,
70
- aliases: "-B",
71
- banner: "Turn off warning when Bundler is not present"
72
-
73
- method_option :show_deprecations,
74
- type: :boolean,
75
- default: false,
76
- banner: "Turn on deprecation warnings"
77
-
78
- # Listen options
79
- method_option :latency,
80
- type: :numeric,
81
- aliases: "-l",
82
- banner: 'Overwrite Listen\'s default latency'
83
-
84
- method_option :force_polling,
85
- type: :boolean,
86
- default: false,
87
- aliases: "-p",
88
- banner: "Force usage of the Listen polling listener"
89
-
90
- method_option :wait_for_delay,
91
- type: :numeric,
92
- aliases: "-y",
93
- banner: 'Overwrite Listen\'s default wait_for_delay'
94
-
95
- method_option :listen_on,
96
- type: :string,
97
- aliases: "-o",
98
- default: false,
99
- banner: "Specify a network address to Listen on for "\
100
- "file change events (e.g. for use in VMs)"
101
-
102
- # Start Guard by initializing the defined Guard plugins and watch the file
103
- # system.
104
- #
105
- # This is the default task, so calling `guard` is the same as calling
106
- # `guard start`.
107
- #
108
- # @see Guard.start
109
- #
110
- def start
111
- _verify_bundler_presence unless options[:no_bundler_warning]
112
- ::Guard.start(options)
113
- end
114
-
115
- desc "list", "Lists Guard plugins that can be used with init"
116
-
117
- # List the Guard plugins that are available for use in your system and
118
- # marks those that are currently used in your `Guardfile`.
119
- #
120
- # @see Guard::DslDescriber.list
121
- #
122
- def list
123
- ::Guard::DslDescriber.new(options).list
124
- end
125
-
126
- desc "notifiers", "Lists notifiers and its options"
127
-
128
- # List the Notifiers for use in your system.
129
- #
130
- # @see Guard::DslDescriber.notifiers
131
- #
132
- def notifiers
133
- ::Guard::DslDescriber.new(options).notifiers
134
- end
135
-
136
- desc "version", "Show the Guard version"
137
- map %w(-v --version) => :version
138
-
139
- # Shows the current version of Guard.
140
- #
141
- # @see Guard::VERSION
142
- #
143
- def version
144
- STDOUT.puts "Guard version #{ ::Guard::VERSION }"
145
- end
146
-
147
- desc "init [GUARDS]", "Generates a Guardfile at the current directory"\
148
- " (if it is not already there) and adds all installed Guard plugins"\
149
- " or the given GUARDS into it"
150
-
151
- method_option :bare,
152
- type: :boolean,
153
- default: false,
154
- aliases: "-b",
155
- banner: "Generate a bare Guardfile without adding any"\
156
- " installed plugin into it"
157
-
158
- # Initializes the templates of all installed Guard plugins and adds them
159
- # to the `Guardfile` when no Guard name is passed. When passing
160
- # Guard plugin names it does the same but only for those Guard plugins.
161
- #
162
- # @see Guard::Guardfile.initialize_template
163
- # @see Guard::Guardfile.initialize_all_templates
164
- #
165
- # @param [Array<String>] plugin_names the name of the Guard plugins to
166
- # initialize
167
- #
168
- def init(*plugin_names)
169
- _verify_bundler_presence unless options[:no_bundler_warning]
170
-
171
- ::Guard::Guardfile.create_guardfile(abort_on_existence: options[:bare])
172
-
173
- return if options[:bare]
174
-
175
- if plugin_names.empty?
176
- ::Guard::Guardfile.initialize_all_templates
177
- else
178
- plugin_names.each do |plugin_name|
179
- ::Guard::Guardfile.initialize_template(plugin_name)
180
- end
181
- end
182
- end
183
-
184
- desc "show", "Show all defined Guard plugins and their options"
185
- map %w(-T) => :show
186
-
187
- # Shows all Guard plugins and their options that are defined in
188
- # the `Guardfile`
189
- #
190
- # @see Guard::DslDescriber.show
191
- #
192
- def show
193
- ::Guard::DslDescriber.new(options).show
194
- end
195
-
196
- private
197
-
198
- # Verifies if Guard is run with `bundle exec` and
199
- # shows a hint to do so if not.
200
- #
201
- def _verify_bundler_presence
202
- return unless File.exist?("Gemfile")
203
- return if ENV["BUNDLE_GEMFILE"] || ENV["RUBYGEMS_GEMDEPS"]
204
-
205
- ::Guard::UI.info <<EOF
206
-
207
- Guard here! It looks like your project has a Gemfile, yet you are running
208
- `guard` outside of Bundler. If this is your intent, feel free to ignore this
209
- message. Otherwise, consider using `bundle exec guard` to ensure your
210
- dependencies are loaded correctly.
211
- (You can run `guard` with --no-bundler-warning to get rid of this message.)
212
- EOF
213
- end
214
- end
215
- end