guard 2.10.5 → 2.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/guard.rb +0 -3
  3. data/lib/guard/aruba_adapter.rb +6 -6
  4. data/lib/guard/cli.rb +5 -0
  5. data/lib/guard/commander.rb +1 -1
  6. data/lib/guard/commands/all.rb +2 -2
  7. data/lib/guard/commands/notification.rb +1 -1
  8. data/lib/guard/commands/reload.rb +2 -2
  9. data/lib/guard/commands/show.rb +1 -1
  10. data/lib/guard/deprecated/evaluator.rb +3 -1
  11. data/lib/guard/deprecated/guard.rb +57 -2
  12. data/lib/guard/dsl.rb +2 -3
  13. data/lib/guard/dsl_describer.rb +8 -20
  14. data/lib/guard/guardfile/evaluator.rb +5 -5
  15. data/lib/guard/guardfile/generator.rb +3 -3
  16. data/lib/guard/internals/debugging.rb +5 -5
  17. data/lib/guard/internals/session.rb +19 -8
  18. data/lib/guard/internals/state.rb +0 -13
  19. data/lib/guard/jobs/pry_wrapper.rb +5 -5
  20. data/lib/guard/notifier.rb +43 -219
  21. data/lib/guard/plugin_util.rb +1 -1
  22. data/lib/guard/terminal.rb +3 -2
  23. data/lib/guard/ui.rb +7 -2
  24. data/lib/guard/version.rb +1 -1
  25. data/lib/guard/watcher.rb +3 -3
  26. metadata +30 -15
  27. data/lib/guard/notifier/detected.rb +0 -87
  28. data/lib/guard/notifiers/base.rb +0 -221
  29. data/lib/guard/notifiers/emacs.rb +0 -99
  30. data/lib/guard/notifiers/file_notifier.rb +0 -54
  31. data/lib/guard/notifiers/gntp.rb +0 -111
  32. data/lib/guard/notifiers/growl.rb +0 -104
  33. data/lib/guard/notifiers/libnotify.rb +0 -86
  34. data/lib/guard/notifiers/notifysend.rb +0 -110
  35. data/lib/guard/notifiers/rb_notifu.rb +0 -100
  36. data/lib/guard/notifiers/terminal_notifier.rb +0 -90
  37. data/lib/guard/notifiers/terminal_title.rb +0 -31
  38. data/lib/guard/notifiers/tmux.rb +0 -335
  39. data/lib/guard/sheller.rb +0 -143
@@ -5,7 +5,7 @@ require "guard/commands/pause"
5
5
  require "guard/commands/reload"
6
6
  require "guard/commands/scope"
7
7
  require "guard/commands/show"
8
- require "guard/sheller"
8
+ require "shellany/sheller"
9
9
 
10
10
  require "guard/jobs/base"
11
11
 
@@ -14,22 +14,22 @@ module Guard
14
14
  class TerminalSettings
15
15
  def initialize
16
16
  @settings = nil
17
- @works = Sheller.run("hash", "stty") || false
17
+ @works = Shellany::Sheller.run("hash", "stty") || false
18
18
  end
19
19
 
20
20
  def restore
21
21
  return unless configurable? && @settings
22
- Sheller.run("stty #{ @setting } 2>#{IO::NULL}")
22
+ Shellany::Sheller.run("stty #{ @setting } 2>#{IO::NULL}")
23
23
  end
24
24
 
25
25
  def save
26
26
  return unless configurable?
27
- @settings = Sheller.stdout("stty -g 2>#{IO::NULL}").chomp
27
+ @settings = Shellany::Sheller.stdout("stty -g 2>#{IO::NULL}").chomp
28
28
  end
29
29
 
30
30
  def echo
31
31
  return unless configurable?
32
- Sheller.run("stty echo 2>#{IO::NULL}")
32
+ Shellany::Sheller.run("stty echo 2>#{IO::NULL}")
33
33
  end
34
34
 
35
35
  def configurable?
@@ -1,246 +1,70 @@
1
- require "yaml"
2
- require "rbconfig"
3
- require "pathname"
4
- require "nenv"
5
-
6
- require_relative "notifier/detected"
7
-
8
- require_relative "ui"
1
+ require "notiffany/notifier"
2
+ require "guard/ui"
9
3
 
10
4
  module Guard
11
- # The notifier handles sending messages to different notifiers. Currently the
12
- # following libraries are supported:
13
- #
14
- # * Ruby GNTP
15
- # * Growl
16
- # * Libnotify
17
- # * rb-notifu
18
- # * emacs
19
- # * Terminal Notifier
20
- # * Terminal Title
21
- # * Tmux
22
- #
23
- # Please see the documentation of each notifier for more information about
24
- # the requirements
25
- # and configuration possibilities.
26
- #
27
- # Guard knows four different notification types:
28
- #
29
- # * success
30
- # * pending
31
- # * failed
32
- # * notify
33
- #
34
- # The notification type selection is based on the image option that is
35
- # sent to {#notify}. Each image type has its own notification type, and
36
- # notifications with custom images goes all sent as type `notify`. The
37
- # `gntp` notifier is able to register these types
38
- # at Growl and allows customization of each notification type.
39
- #
40
- # Guard can be configured to make use of more than one notifier at once.
41
- #
42
- # @see Guard::Dsl
43
- #
44
- # TODO: rename to plural
45
- module Notifier
46
- extend self
47
-
48
- NOTIFICATIONS_DISABLED = "Notifications disabled by GUARD_NOTIFY" +
49
- " environment variable"
50
-
51
- USING_NOTIFIER = "Guard is using %s to send notifications."
52
-
53
- ONLY_NOTIFY = "Only notify() is available from a child process"
54
-
55
- DEPRECTED_IMPLICIT_CONNECT = "Calling Guard::Notifier.notify()" +
56
- " without a prior Notifier.connect() is deprecated"
57
-
58
- # List of available notifiers, grouped by functionality
59
- SUPPORTED = [
60
- {
61
- gntp: GNTP,
62
- growl: Growl,
63
- terminal_notifier: TerminalNotifier,
64
- libnotify: Libnotify,
65
- notifysend: NotifySend,
66
- notifu: Notifu
67
- },
68
- { emacs: Emacs },
69
- { tmux: Tmux },
70
- { terminal_title: TerminalTitle },
71
- { file: FileNotifier }
72
- ]
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
-
82
- class NotServer < RuntimeError
83
- end
84
-
85
- def connect(options = {})
86
- @detected = Detected.new(SUPPORTED)
87
- return if _client?
88
-
89
- _env.notify_pid = $$
90
-
91
- fail "Already connected" if active?
92
-
93
- return unless enabled? && options[:notify]
94
-
95
- @detected.detect
96
-
97
- turn_on
98
- rescue Detected::NoneAvailableError => e
99
- ::Guard::UI.info e.to_s
100
- end
101
-
102
- def disconnect
103
- if _client?
104
- @detected = nil
105
- return
5
+ class Notifier
6
+ def self.connect(options = {})
7
+ @notifier ||= nil
8
+ fail "Already connected!" if @notifier
9
+ begin
10
+ opts = options.merge(namespace: "guard", logger: UI)
11
+ @notifier = Notiffany.connect(opts)
12
+ rescue Notiffany::Notifier::Detected::UnknownNotifier => e
13
+ UI.error "Failed to setup notification: #{e.message}"
14
+ fail
106
15
  end
107
-
108
- turn_off if active?
109
- @detected.reset unless @detected.nil?
110
- _env.notify_pid = nil
111
- @detected = nil
112
16
  end
113
17
 
114
- # Turn notifications on.
115
- #
116
- # @param [Hash] options the turn_on options
117
- # @option options [Boolean] silent disable any logging
118
- #
119
- def turn_on(options = {})
120
- _check_server!
121
- return unless enabled?
122
-
123
- fail "Already active!" if active?
18
+ def self.disconnect
19
+ @notifier.disconnect
20
+ @notifier = nil
21
+ end
124
22
 
125
- silent = options[:silent]
23
+ DEPRECATED_IMPLICIT_CONNECT = "Calling Notiffany::Notifier.notify()" +
24
+ " without a prior Notifier.connect() is deprecated"
126
25
 
127
- @detected.available.each do |klass, _|
128
- ::Guard::UI.info(format(USING_NOTIFIER, klass.title)) unless silent
129
- klass.turn_on if klass.respond_to?(:turn_on)
26
+ def self.notify(message, options)
27
+ unless @notifier
28
+ # TODO: reenable again?
29
+ # UI.deprecation(DEPRECTED_IMPLICIT_CONNECT)
30
+ connect(notify: true)
130
31
  end
131
32
 
132
- _env.notify_active = true
33
+ @notifier.notify(message, options)
34
+ rescue RuntimeError => e
35
+ UI.error "Notification failed for #{notifier.name}: #{e.message}"
36
+ UI.debug e.backtrace.join("\n")
133
37
  end
134
38
 
135
- # Turn notifications off.
136
- def turn_off
137
- _check_server!
138
-
139
- fail "Not active!" unless active?
140
-
141
- @detected.available.each do |klass, _|
142
- klass.turn_off if klass.respond_to?(:turn_off)
143
- end
144
-
145
- _env.notify_active = false
39
+ def self.turn_on
40
+ @notifier.turn_on
146
41
  end
147
42
 
148
- # Toggle the system notifications on/off
149
- def toggle
150
- unless enabled?
151
- ::Guard::UI.error NOTIFICATIONS_DISABLED
43
+ def self.toggle
44
+ unless @notifier.enabled?
45
+ UI.error NOTIFICATIONS_DISABLED
152
46
  return
153
47
  end
154
48
 
155
- if active?
156
- ::Guard::UI.info "Turn off notifications"
157
- turn_off
49
+ if @notifier.active?
50
+ UI.info "Turn off notifications"
51
+ @notifier.turn_off
158
52
  return
159
53
  end
160
54
 
161
- turn_on
162
- end
163
-
164
- # Test if the notifications can be enabled based on ENV['GUARD_NOTIFY']
165
- def enabled?
166
- _env.notify?
167
- end
168
-
169
- # Test if notifiers are currently turned on
170
- def active?
171
- _env.notify_active?
172
- end
173
-
174
- # Add a notification library to be used.
175
- #
176
- # @param [Symbol] name the name of the notifier to use
177
- # @param [Hash] options the notifier options
178
- # @option options [String] silent disable any error message
179
- # @return [Boolean] if the notification could be added
180
- #
181
- def add(name, options = {})
182
- _check_server!
183
-
184
- return false unless enabled?
185
-
186
- if name == :off && active?
187
- turn_off
188
- return false
189
- end
190
-
191
- # ok to pass new instance when called without connect (e.g. evaluator)
192
- (@detected || Detected.new(SUPPORTED)).add(name, options)
193
- end
194
-
195
- # TODO: deprecate/remove
196
- alias :add_notifier :add
197
-
198
- # Show a system notification with all configured notifiers.
199
- #
200
- # @param [String] message the message to show
201
- # @option opts [Symbol, String] image the image symbol or path to an image
202
- # @option opts [String] title the notification title
203
- #
204
- def notify(message, message_opts = {})
205
- if _client?
206
- # TODO: reenable again?
207
- # UI.deprecation(DEPRECTED_IMPLICIT_CONNECT)
208
- return unless enabled?
209
- connect(notify: true)
210
- else
211
- return unless active?
212
- end
213
-
214
- @detected.available.each do |klass, options|
215
- _notify(klass, options, message, message_opts)
216
- end
55
+ @notifier.turn_on
217
56
  end
218
57
 
219
58
  # Used by dsl describer
220
- def notifiers
221
- @detected.available.map { |mod, opts| { name: mod.name, options: opts } }
222
- end
223
-
224
- private
225
-
226
- def _env
227
- @environment ||= Env.new("guard")
59
+ def self.supported
60
+ Notiffany::Notifier::SUPPORTED.inject(:merge)
228
61
  end
229
62
 
230
- def _check_server!
231
- _client? && fail(NotServer, ONLY_NOTIFY)
232
- end
233
-
234
- def _client?
235
- (pid = _env.notify_pid) && (pid != $$)
236
- end
237
-
238
- def _notify(klass, options, message, message_options)
239
- notifier = klass.new(options)
240
- notifier.notify(message, message_options.dup)
241
- rescue RuntimeError => e
242
- ::Guard::UI.error "Notification failed for #{notifier.name}: #{e.message}"
243
- ::Guard::UI.debug e.backtrace.join("\n")
63
+ # Used by dsl describer
64
+ def self.detected
65
+ @notifier.available.map do |mod|
66
+ { name: mod.name.to_sym, options: mod.options }
67
+ end
244
68
  end
245
69
  end
246
70
  end
@@ -73,7 +73,7 @@ module Guard
73
73
  def plugin_location
74
74
  @plugin_location ||= _full_gem_path("guard-#{name}")
75
75
  rescue Gem::LoadError
76
- ::Guard::UI.error "Could not find 'guard-#{ name }' gem path."
76
+ UI.error "Could not find 'guard-#{ name }' gem path."
77
77
  end
78
78
 
79
79
  # Tries to load the Guard plugin main class. This transforms the supplied
@@ -1,10 +1,11 @@
1
- require "guard/sheller"
1
+ require "shellany/sheller"
2
+
2
3
  module Guard
3
4
  class Terminal
4
5
  class << self
5
6
  def clear
6
7
  cmd = Gem.win_platform? ? "cls" : "clear;"
7
- exit_code, _, stderr = ::Guard::Sheller.system(cmd)
8
+ exit_code, _, stderr = Shellany::Sheller.system(cmd)
8
9
  fail Errno::ENOENT, stderr unless exit_code == 0
9
10
  end
10
11
  end
@@ -1,6 +1,11 @@
1
1
  require "guard/ui/colors"
2
2
 
3
3
  require "guard/terminal"
4
+ require "guard/options"
5
+
6
+ # TODO: rework this class from the bottom-up
7
+ # - remove dependency on Session and Scope
8
+ # - extract into a separate gem
4
9
 
5
10
  module Guard
6
11
  # The UI class helps to format messages for the user. Everything that is
@@ -37,7 +42,7 @@ module Guard
37
42
  # @return [Hash] the logger options
38
43
  #
39
44
  def options
40
- @options ||= ::Guard::Options.new(
45
+ @options ||= Options.new(
41
46
  level: :info,
42
47
  template: ":time - :severity - :message",
43
48
  time_format: "%H:%M:%S")
@@ -52,7 +57,7 @@ module Guard
52
57
  #
53
58
  # TODO: deprecate?
54
59
  def options=(options)
55
- @options = ::Guard::Options.new(options)
60
+ @options = Options.new(options)
56
61
  end
57
62
 
58
63
  # Assigns a log level
@@ -1,3 +1,3 @@
1
1
  module Guard
2
- VERSION = "2.10.5"
2
+ VERSION = "2.11.0"
3
3
  end
@@ -29,8 +29,8 @@ module Guard
29
29
  return unless @pattern.is_a?(String) && @pattern =~ regexp
30
30
 
31
31
  unless @@warning_printed
32
- ::Guard::UI.info "*" * 20 + "\nDEPRECATION WARNING!\n" + "*" * 20
33
- ::Guard::UI.info <<-MSG
32
+ UI.info "*" * 20 + "\nDEPRECATION WARNING!\n" + "*" * 20
33
+ UI.info <<-MSG
34
34
  You have a string in your Guardfile watch patterns that seem to
35
35
  represent a Regexp.
36
36
 
@@ -43,7 +43,7 @@ module Guard
43
43
  end
44
44
 
45
45
  new_regexp = Regexp.new(@pattern).inspect
46
- ::Guard::UI.info "\"#{@pattern}\" has been converted to #{ new_regexp }\n"
46
+ UI.info "\"#{@pattern}\" has been converted to #{ new_regexp }\n"
47
47
  @pattern = Regexp.new(@pattern)
48
48
  end
49
49
 
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.10.5
4
+ version: 2.11.0
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-12-22 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: shellany
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: notiffany
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.0'
97
125
  description: Guard is a command line tool to easily handle events on file system modifications.
98
126
  email:
99
127
  - thibaud@thibaud.gg
@@ -151,24 +179,11 @@ files:
151
179
  - lib/guard/jobs/pry_wrapper.rb
152
180
  - lib/guard/jobs/sleep.rb
153
181
  - lib/guard/notifier.rb
154
- - lib/guard/notifier/detected.rb
155
- - lib/guard/notifiers/base.rb
156
- - lib/guard/notifiers/emacs.rb
157
- - lib/guard/notifiers/file_notifier.rb
158
- - lib/guard/notifiers/gntp.rb
159
- - lib/guard/notifiers/growl.rb
160
- - lib/guard/notifiers/libnotify.rb
161
- - lib/guard/notifiers/notifysend.rb
162
- - lib/guard/notifiers/rb_notifu.rb
163
- - lib/guard/notifiers/terminal_notifier.rb
164
- - lib/guard/notifiers/terminal_title.rb
165
- - lib/guard/notifiers/tmux.rb
166
182
  - lib/guard/options.rb
167
183
  - lib/guard/plugin.rb
168
184
  - lib/guard/plugin_util.rb
169
185
  - lib/guard/rake_task.rb
170
186
  - lib/guard/runner.rb
171
- - lib/guard/sheller.rb
172
187
  - lib/guard/templates/Guardfile
173
188
  - lib/guard/terminal.rb
174
189
  - lib/guard/ui.rb