guard 1.4.0 → 2.18.0

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.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1 -677
  3. data/LICENSE +4 -2
  4. data/README.md +91 -753
  5. data/bin/_guard-core +11 -0
  6. data/bin/guard +108 -3
  7. data/lib/guard/aruba_adapter.rb +59 -0
  8. data/lib/guard/cli/environments/bundler.rb +22 -0
  9. data/lib/guard/cli/environments/evaluate_only.rb +35 -0
  10. data/lib/guard/cli/environments/valid.rb +69 -0
  11. data/lib/guard/cli.rb +129 -128
  12. data/lib/guard/commander.rb +104 -0
  13. data/lib/guard/commands/all.rb +37 -0
  14. data/lib/guard/commands/change.rb +31 -0
  15. data/lib/guard/commands/notification.rb +26 -0
  16. data/lib/guard/commands/pause.rb +29 -0
  17. data/lib/guard/commands/reload.rb +36 -0
  18. data/lib/guard/commands/scope.rb +38 -0
  19. data/lib/guard/commands/show.rb +24 -0
  20. data/lib/guard/config.rb +18 -0
  21. data/lib/guard/deprecated/dsl.rb +45 -0
  22. data/lib/guard/deprecated/evaluator.rb +39 -0
  23. data/lib/guard/deprecated/guard.rb +328 -0
  24. data/lib/guard/deprecated/guardfile.rb +84 -0
  25. data/lib/guard/deprecated/watcher.rb +27 -0
  26. data/lib/guard/dsl.rb +332 -363
  27. data/lib/guard/dsl_describer.rb +132 -122
  28. data/lib/guard/dsl_reader.rb +51 -0
  29. data/lib/guard/group.rb +34 -14
  30. data/lib/guard/guardfile/evaluator.rb +232 -0
  31. data/lib/guard/guardfile/generator.rb +128 -0
  32. data/lib/guard/guardfile.rb +24 -60
  33. data/lib/guard/interactor.rb +31 -255
  34. data/lib/guard/internals/debugging.rb +68 -0
  35. data/lib/guard/internals/groups.rb +40 -0
  36. data/lib/guard/internals/helpers.rb +13 -0
  37. data/lib/guard/internals/plugins.rb +53 -0
  38. data/lib/guard/internals/queue.rb +51 -0
  39. data/lib/guard/internals/scope.rb +121 -0
  40. data/lib/guard/internals/session.rb +180 -0
  41. data/lib/guard/internals/state.rb +25 -0
  42. data/lib/guard/internals/tracing.rb +33 -0
  43. data/lib/guard/internals/traps.rb +10 -0
  44. data/lib/guard/jobs/base.rb +21 -0
  45. data/lib/guard/jobs/pry_wrapper.rb +336 -0
  46. data/lib/guard/jobs/sleep.rb +26 -0
  47. data/lib/guard/notifier.rb +46 -212
  48. data/lib/guard/options.rb +22 -0
  49. data/lib/guard/plugin.rb +303 -0
  50. data/lib/guard/plugin_util.rb +191 -0
  51. data/lib/guard/rake_task.rb +42 -0
  52. data/lib/guard/runner.rb +80 -140
  53. data/lib/guard/templates/Guardfile +14 -0
  54. data/lib/guard/terminal.rb +13 -0
  55. data/lib/guard/ui/colors.rb +56 -0
  56. data/lib/guard/ui/config.rb +70 -0
  57. data/lib/guard/ui/logger.rb +30 -0
  58. data/lib/guard/ui.rb +163 -128
  59. data/lib/guard/version.rb +1 -2
  60. data/lib/guard/watcher/pattern/deprecated_regexp.rb +45 -0
  61. data/lib/guard/watcher/pattern/match_result.rb +18 -0
  62. data/lib/guard/watcher/pattern/matcher.rb +33 -0
  63. data/lib/guard/watcher/pattern/pathname_path.rb +15 -0
  64. data/lib/guard/watcher/pattern/simple_path.rb +23 -0
  65. data/lib/guard/watcher/pattern.rb +24 -0
  66. data/lib/guard/watcher.rb +52 -95
  67. data/lib/guard.rb +108 -376
  68. data/lib/tasks/releaser.rb +116 -0
  69. data/man/guard.1 +12 -9
  70. data/man/guard.1.html +18 -12
  71. metadata +148 -77
  72. data/images/guard.png +0 -0
  73. data/lib/guard/guard.rb +0 -156
  74. data/lib/guard/hook.rb +0 -120
  75. data/lib/guard/interactors/coolline.rb +0 -64
  76. data/lib/guard/interactors/helpers/completion.rb +0 -32
  77. data/lib/guard/interactors/helpers/terminal.rb +0 -46
  78. data/lib/guard/interactors/readline.rb +0 -94
  79. data/lib/guard/interactors/simple.rb +0 -19
  80. data/lib/guard/notifiers/emacs.rb +0 -69
  81. data/lib/guard/notifiers/gntp.rb +0 -118
  82. data/lib/guard/notifiers/growl.rb +0 -99
  83. data/lib/guard/notifiers/growl_notify.rb +0 -92
  84. data/lib/guard/notifiers/libnotify.rb +0 -96
  85. data/lib/guard/notifiers/notifysend.rb +0 -84
  86. data/lib/guard/notifiers/rb_notifu.rb +0 -102
  87. data/lib/guard/notifiers/terminal_notifier.rb +0 -66
  88. data/lib/guard/notifiers/tmux.rb +0 -69
  89. data/lib/guard/version.rbc +0 -130
data/lib/guard/watcher.rb CHANGED
@@ -1,131 +1,88 @@
1
- module Guard
1
+ require "guard/config"
2
+ require "guard/deprecated/watcher" unless Guard::Config.new.strict?
3
+
4
+ require "guard/ui"
5
+ require "guard/watcher/pattern"
2
6
 
3
- # The watcher defines a RegExp that will be matched against file system modifications.
4
- # When a watcher matches a change, an optional action block is executed to enable
5
- # processing the file system change result.
7
+ module Guard
8
+ # The watcher defines a RegExp that will be matched against file system
9
+ # modifications.
10
+ # When a watcher matches a change, an optional action block is executed to
11
+ # enable processing the file system change result.
6
12
  #
7
13
  class Watcher
8
-
9
- require 'guard/ui'
10
-
14
+ Deprecated::Watcher.add_deprecated(self) unless Config.new.strict?
11
15
  attr_accessor :pattern, :action
12
16
 
13
- # Initialize a file watcher.
17
+ # Initializes a file watcher.
14
18
  #
15
- # @param [String, Regexp] pattern the pattern to be watched by the Guard plugin
16
- # @param [Block] action the action to execute before passing the result to the Guard plugin
19
+ # @param [String, Regexp] pattern the pattern to be watched by the Guard
20
+ # plugin
21
+ # @param [Block] action the action to execute before passing the result to
22
+ # the Guard plugin
17
23
  #
18
24
  def initialize(pattern, action = nil)
19
- @pattern, @action = pattern, action
20
- @@warning_printed ||= false
21
-
22
- # deprecation warning
23
- if @pattern.is_a?(String) && @pattern =~ /(^(\^))|(>?(\\\.)|(\.\*))|(\(.*\))|(\[.*\])|(\$$)/
24
- unless @@warning_printed
25
- ::Guard::UI.info "*"*20 + "\nDEPRECATION WARNING!\n" + "*"*20
26
- ::Guard::UI.info <<-MSG
27
- You have a string in your Guardfile watch patterns that seem to represent a Regexp.
28
- Guard matches String with == and Regexp with Regexp#match.
29
- You should either use plain String (without Regexp special characters) or real Regexp.
30
- MSG
31
- @@warning_printed = true
32
- end
25
+ @action = action
26
+ @pattern = Pattern.create(pattern)
27
+ end
33
28
 
34
- ::Guard::UI.info "\"#{@pattern}\" has been converted to #{ Regexp.new(@pattern).inspect }\n"
35
- @pattern = Regexp.new(@pattern)
36
- end
29
+ # Compare with other watcher
30
+ # @param other [Guard::Watcher] other watcher for comparing
31
+ # @return [true, false] equal or not
32
+ def ==(other)
33
+ action == other.action && pattern == other.pattern
37
34
  end
38
35
 
39
- # Finds the files that matches a Guard.
36
+ # Finds the files that matches a Guard plugin.
40
37
  #
41
- # @param [Guard::Guard] guard the Guard plugin which watchers are used
38
+ # @param [Guard::Plugin] guard the Guard plugin which watchers are used
42
39
  # @param [Array<String>] files the changed files
43
40
  # @return [Array<Object>] the matched watcher response
44
41
  #
45
42
  def self.match_files(guard, files)
46
43
  return [] if files.empty?
47
- guard.watchers.inject([]) do |paths, watcher|
48
- files.each do |file|
49
- if matches = watcher.match(file)
50
- if watcher.action
51
- result = watcher.call_action(matches)
52
- if guard.options[:any_return]
53
- paths << result
54
- elsif result.respond_to?(:empty?) && !result.empty?
55
- paths << Array(result)
56
- end
44
+
45
+ files.inject([]) do |paths, file|
46
+ guard.watchers.each do |watcher|
47
+ matches = watcher.match(file)
48
+ next(paths) unless matches
49
+
50
+ if watcher.action
51
+ result = watcher.call_action(matches)
52
+ if guard.options[:any_return]
53
+ paths << result
54
+ elsif result.respond_to?(:empty?) && !result.empty?
55
+ paths << Array(result)
57
56
  else
58
- paths << matches[0]
57
+ next(paths)
59
58
  end
59
+ else
60
+ paths << matches[0]
60
61
  end
61
- end
62
-
63
- guard.options[:any_return] ? paths : paths.flatten.map { |p| p.to_s }
64
- end
65
- end
66
62
 
67
- # Test if a file would be matched by any of the Guard plugin watchers.
68
- #
69
- # @param [Array<Guard::Guard>] guards the Guard plugins to use the watchers from
70
- # @param [Array<String>] files the files to test
71
- # @return [Boolean] Whether a file matches
72
- #
73
- def self.match_files?(guards, files)
74
- guards.any? do |guard|
75
- guard.watchers.any? do |watcher|
76
- files.any? { |file| watcher.match(file) }
63
+ break if guard.options[:first_match]
77
64
  end
78
- end
79
- end
80
-
81
- # @deprecated Use .match instead
82
- #
83
- def match_file?(file)
84
- ::Guard::UI.info "Guard::Watcher.match_file? is deprecated, please use Guard::Watcher.match instead."
85
- match(file)
86
- end
87
65
 
88
- # Test the watchers pattern against a file.
89
- #
90
- # @param [String] file the file to test
91
- # @return [Array<String>] an array of matches (or containing a single path if the pattern is a string)
92
- #
93
- def match(file)
94
- f = file
95
- deleted = file.start_with?('!')
96
- f = deleted ? f[1..-1] : f
97
- if @pattern.is_a?(Regexp)
98
- if m = f.match(@pattern)
99
- m = m.to_a
100
- m[0] = file
101
- m
102
- end
103
- else
104
- f == @pattern ? [file] : nil
66
+ guard.options[:any_return] ? paths : paths.flatten.map(&:to_s)
105
67
  end
106
68
  end
107
69
 
108
- # Test if any of the files is the Guardfile.
109
- #
110
- # @param [Array<String>] files the files to test
111
- # @return [Boolean] whether one of these files is the Guardfile
112
- #
113
- def self.match_guardfile?(files)
114
- files.any? { |file| "#{ Dir.pwd }/#{ file }" == Dsl.guardfile_path }
70
+ def match(string_or_pathname)
71
+ m = pattern.match(string_or_pathname)
72
+ m.nil? ? nil : Pattern::MatchResult.new(m, string_or_pathname)
115
73
  end
116
74
 
117
75
  # Executes a watcher action.
118
76
  #
119
- # @param [String, MatchData] matches the matched path or the match from the Regex
77
+ # @param [String, MatchData] matches the matched path or the match from the
78
+ # Regex
120
79
  # @return [String] the final paths
121
80
  #
122
81
  def call_action(matches)
123
- begin
124
- @action.arity > 0 ? @action.call(matches) : @action.call
125
- rescue Exception => e
126
- ::Guard::UI.error "Problem with watch action!\n#{ e.message }\n\n#{ e.backtrace.join("\n") }"
127
- end
82
+ @action.arity > 0 ? @action.call(matches) : @action.call
83
+ rescue => ex
84
+ UI.error "Problem with watch action!\n#{ex.message}"
85
+ UI.error ex.backtrace.join("\n")
128
86
  end
129
-
130
87
  end
131
88
  end