guard 1.8.3 → 2.0.0.pre

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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +68 -10
  3. data/README.md +54 -33
  4. data/lib/guard.rb +133 -483
  5. data/lib/guard/cli.rb +78 -82
  6. data/lib/guard/commander.rb +121 -0
  7. data/lib/guard/commands/all.rb +1 -1
  8. data/lib/guard/commands/reload.rb +1 -1
  9. data/lib/guard/deprecated_methods.rb +59 -0
  10. data/lib/guard/deprecator.rb +107 -0
  11. data/lib/guard/dsl.rb +143 -329
  12. data/lib/guard/dsl_describer.rb +101 -57
  13. data/lib/guard/group.rb +27 -8
  14. data/lib/guard/guard.rb +25 -150
  15. data/lib/guard/guardfile.rb +35 -85
  16. data/lib/guard/guardfile/evaluator.rb +245 -0
  17. data/lib/guard/guardfile/generator.rb +89 -0
  18. data/lib/guard/interactor.rb +147 -163
  19. data/lib/guard/notifier.rb +83 -137
  20. data/lib/guard/notifiers/base.rb +220 -0
  21. data/lib/guard/notifiers/emacs.rb +39 -37
  22. data/lib/guard/notifiers/file_notifier.rb +29 -25
  23. data/lib/guard/notifiers/gntp.rb +68 -75
  24. data/lib/guard/notifiers/growl.rb +49 -52
  25. data/lib/guard/notifiers/growl_notify.rb +51 -56
  26. data/lib/guard/notifiers/libnotify.rb +41 -48
  27. data/lib/guard/notifiers/notifysend.rb +58 -38
  28. data/lib/guard/notifiers/rb_notifu.rb +54 -54
  29. data/lib/guard/notifiers/terminal_notifier.rb +48 -36
  30. data/lib/guard/notifiers/terminal_title.rb +23 -19
  31. data/lib/guard/notifiers/tmux.rb +110 -93
  32. data/lib/guard/options.rb +21 -0
  33. data/lib/guard/plugin.rb +66 -0
  34. data/lib/guard/plugin/base.rb +178 -0
  35. data/lib/guard/plugin/hooker.rb +123 -0
  36. data/lib/guard/plugin_util.rb +158 -0
  37. data/lib/guard/rake_task.rb +47 -0
  38. data/lib/guard/runner.rb +62 -82
  39. data/lib/guard/setuper.rb +248 -0
  40. data/lib/guard/ui.rb +24 -80
  41. data/lib/guard/ui/colors.rb +60 -0
  42. data/lib/guard/version.rb +1 -2
  43. data/lib/guard/watcher.rb +30 -30
  44. data/man/guard.1 +4 -4
  45. data/man/guard.1.html +6 -4
  46. metadata +25 -11
  47. data/lib/guard/hook.rb +0 -120
@@ -1,5 +1,4 @@
1
- require 'rbconfig'
2
- require 'guard/ui'
1
+ require 'guard/notifiers/base'
3
2
 
4
3
  module Guard
5
4
  module Notifier
@@ -18,76 +17,72 @@ module Guard
18
17
  # notification :growl_notify
19
18
  #
20
19
  # @example Add the `:growl_notify` notifier with configuration options to your `Guardfile`
21
- # notification :growl_notify, :sticky => true
20
+ # notification :growl_notify, sticky: true
22
21
  #
23
- module GrowlNotify
24
- extend self
22
+ class GrowlNotify < Base
25
23
 
26
- # Default options for growl_notify gem
24
+ # Default options for the growl_notify notifications.
27
25
  DEFAULTS = {
28
- :sticky => false,
29
- :priority => 0
26
+ sticky: false,
27
+ priority: 0
30
28
  }
31
29
 
32
- # Test if the notification library is available.
30
+ def self.supported_hosts
31
+ %w[darwin]
32
+ end
33
+
34
+ def self.available?(opts = {})
35
+ super
36
+ _register!(opts) if require_gem_safely(opts)
37
+ end
38
+
39
+ # Shows a system notification.
33
40
  #
34
- # @param [Boolean] silent true if no error messages should be shown
35
- # @param [Hash] options notifier options
36
- # @return [Boolean] the availability status
41
+ # @param [String] message the notification message body
42
+ # @param [Hash] opts additional notification library options
43
+ # @option opts [String] type the notification type. Either 'success',
44
+ # 'pending', 'failed' or 'notify'
45
+ # @option opts [String] title the notification title
46
+ # @option opts [String] image the path to the notification image
47
+ # @option opts [Boolean] sticky if the message should stick to the screen
48
+ # @option opts [Integer] priority the importance of message from -2 (very
49
+ # low) to 2 (emergency)
37
50
  #
38
- def available?(silent = false, options = {})
39
- if RbConfig::CONFIG['host_os'] =~ /darwin/
40
- require 'growl_notify'
51
+ def notify(message, opts = {})
52
+ self.class.require_gem_safely
53
+ normalize_standard_options!(opts)
41
54
 
42
- begin
43
- if ::GrowlNotify.application_name != 'Guard'
44
- ::GrowlNotify.config do |c|
45
- c.notifications = %w(success pending failed notify)
46
- c.default_notifications = 'notify'
47
- c.application_name = 'Guard'
48
- end
49
- end
55
+ opts = DEFAULTS.merge(
56
+ application_name: 'Guard',
57
+ with_name: opts.delete(:type).to_s,
58
+ description: message,
59
+ icon: opts.delete(:image)
60
+ ).merge(opts)
50
61
 
51
- true
62
+ ::GrowlNotify.send_notification(opts)
63
+ end
52
64
 
53
- rescue ::GrowlNotify::GrowlNotFound
54
- ::Guard::UI.error 'Please install Growl from http://growl.info' unless silent
55
- false
65
+ # @private
66
+ #
67
+ def self._register!(options)
68
+ if ::GrowlNotify.application_name != 'Guard'
69
+ ::GrowlNotify.config do |c|
70
+ c.notifications = %w(success pending failed notify)
71
+ c.default_notifications = 'notify'
72
+ c.application_name = 'Guard'
56
73
  end
57
-
58
- else
59
- ::Guard::UI.error 'The :growl_notify notifier runs only on Mac OS X.' unless silent
60
- false
61
74
  end
62
75
 
63
- rescue LoadError, NameError
64
- ::Guard::UI.error "Please add \"gem 'growl_notify'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
65
- false
66
- end
67
-
68
- # Show a system notification.
69
- #
70
- # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
71
- # @param [String] title the notification title
72
- # @param [String] message the notification message body
73
- # @param [String] image the path to the notification image
74
- # @param [Hash] options additional notification library options
75
- # @option options [Boolean] sticky if the message should stick to the screen
76
- # @option options [Integer] priority the importance of message from -2 (very low) to 2 (emergency)
77
- #
78
- def notify(type, title, message, image, options = { })
79
- require 'growl_notify'
76
+ true
80
77
 
81
- ::GrowlNotify.send_notification(DEFAULTS.merge(options).merge({
82
- :application_name => 'Guard',
83
- :with_name => type,
84
- :title => title,
85
- :description => message,
86
- :icon => image
87
- }))
78
+ rescue ::GrowlNotify::GrowlNotFound
79
+ unless options[:silent]
80
+ ::Guard::UI.error 'Please install Growl from http://growl.info'
81
+ end
82
+ false
88
83
  end
89
84
 
90
85
  end
86
+
91
87
  end
92
88
  end
93
-
@@ -1,12 +1,13 @@
1
- require 'rbconfig'
2
- require 'guard/ui'
1
+ require 'guard/notifiers/base'
3
2
 
4
3
  module Guard
5
4
  module Notifier
6
5
 
7
- # System notifications using the [libnotify](https://github.com/splattael/libnotify) gem.
6
+ # System notifications using the
7
+ # [libnotify](https://github.com/splattael/libnotify) gem.
8
8
  #
9
- # This gem is available for Linux, FreeBSD, OpenBSD and Solaris and sends system notifications to
9
+ # This gem is available for Linux, FreeBSD, OpenBSD and Solaris and sends
10
+ # system notifications to
10
11
  # Gnome [libnotify](http://developer.gnome.org/libnotify):
11
12
  #
12
13
  # @example Add the `libnotify` gem to your `Gemfile`
@@ -18,61 +19,52 @@ module Guard
18
19
  # notification :libnotify
19
20
  #
20
21
  # @example Add the `:libnotify` notifier with configuration options to your `Guardfile`
21
- # notification :libnotify, :timeout => 5, :transient => true, :append => false, :urgency => :critical
22
+ # notification :libnotify, timeout: 5, transient: true, append: false, urgency: :critical
22
23
  #
23
- module Libnotify
24
- extend self
24
+ class Libnotify < Base
25
25
 
26
- # Default options for libnotify gem
26
+ # Default options for the libnotify notifications.
27
27
  DEFAULTS = {
28
- :transient => false,
29
- :append => true,
30
- :timeout => 3
28
+ transient: false,
29
+ append: true,
30
+ timeout: 3
31
31
  }
32
32
 
33
- # Test if the notification library is available.
34
- #
35
- # @param [Boolean] silent true if no error messages should be shown
36
- # @param [Hash] options notifier options
37
- # @return [Boolean] the availability status
38
- #
39
- def available?(silent = false, options = {})
40
- if RbConfig::CONFIG['host_os'] =~ /linux|freebsd|openbsd|sunos|solaris/
41
- require 'libnotify'
42
-
43
- true
44
-
45
- else
46
- ::Guard::UI.error 'The :libnotify notifier runs only on Linux, FreeBSD, OpenBSD and Solaris.' unless silent
47
- false
48
- end
33
+ def self.supported_hosts
34
+ %w[linux freebsd openbsd sunos solaris]
35
+ end
49
36
 
50
- rescue LoadError
51
- ::Guard::UI.error "Please add \"gem 'libnotify'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
52
- false
37
+ def self.available?(opts = {})
38
+ super
39
+ require_gem_safely(opts)
53
40
  end
54
41
 
55
- # Show a system notification.
42
+ # Shows a system notification.
56
43
  #
57
- # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
58
- # @param [String] title the notification title
59
44
  # @param [String] message the notification message body
60
- # @param [String] image the path to the notification image
61
- # @param [Hash] options additional notification library options
62
- # @option options [Boolean] transient keep the notifications around after display
63
- # @option options [Boolean] append append onto existing notification
64
- # @option options [Number, Boolean] timeout the number of seconds to display (1.5 (s), 1000 (ms), false)
45
+ # @param [Hash] opts additional notification library options
46
+ # @option opts [String] type the notification type. Either 'success',
47
+ # 'pending', 'failed' or 'notify'
48
+ # @option opts [String] title the notification title
49
+ # @option opts [String] image the path to the notification image
50
+ # @option opts [Boolean] transient keep the notifications around after
51
+ # display
52
+ # @option opts [Boolean] append append onto existing notification
53
+ # @option opts [Number, Boolean] timeout the number of seconds to display
54
+ # (1.5 (s), 1000 (ms), false)
65
55
  #
66
- def notify(type, title, message, image, options = { })
67
- require 'libnotify'
56
+ def notify(message, opts = {})
57
+ self.class.require_gem_safely
58
+ normalize_standard_options!(opts)
68
59
 
69
- options = DEFAULTS.merge(options).merge({
70
- :summary => title,
71
- :body => message,
72
- :icon_path => image
73
- })
74
- options[:urgency] ||= libnotify_urgency(type)
75
- ::Libnotify.show(options)
60
+ opts = DEFAULTS.merge(
61
+ summary: opts.delete(:title),
62
+ icon_path: opts.delete(:image),
63
+ body: message,
64
+ urgency: _libnotify_urgency(opts.delete(:type))
65
+ ).merge(opts)
66
+
67
+ ::Libnotify.show(opts)
76
68
  end
77
69
 
78
70
  private
@@ -83,7 +75,7 @@ module Guard
83
75
  # @param [String] type the Guard notification type
84
76
  # @return [Symbol] the libnotify urgency
85
77
  #
86
- def libnotify_urgency(type)
78
+ def _libnotify_urgency(type)
87
79
  case type
88
80
  when 'failed'
89
81
  :normal
@@ -93,5 +85,6 @@ module Guard
93
85
  end
94
86
 
95
87
  end
88
+
96
89
  end
97
90
  end
@@ -1,5 +1,4 @@
1
- require 'rbconfig'
2
- require 'guard/ui'
1
+ require 'guard/notifiers/base'
3
2
 
4
3
  module Guard
5
4
  module Notifier
@@ -10,76 +9,97 @@ module Guard
10
9
  # @example Add the `:notifysend` notifier to your `Guardfile`
11
10
  # notification :notifysend
12
11
  #
13
- module NotifySend
14
- extend self
12
+ class NotifySend < Base
15
13
 
16
- # Default options for the notify-send program
14
+ # Default options for the notify-send notifications.
17
15
  DEFAULTS = {
18
- :t => 3000, # Default timeout is 3000ms
19
- :h => 'int:transient:1' # Automatically close the notification
16
+ t: 3000, # Default timeout is 3000ms
17
+ h: 'int:transient:1' # Automatically close the notification
20
18
  }
21
19
 
22
- # Full list of options supported by notify-send
20
+ # Full list of options supported by notify-send.
23
21
  SUPPORTED = [:u, :t, :i, :c, :h]
24
22
 
25
- # Test if the notification program is available.
26
- #
27
- # @param [Boolean] silent true if no error messages should be shown
28
- # @param [Hash] options notifier options
29
- # @return [Boolean] the availability status
30
- #
31
- def available?(silent = false, options = {})
32
- if (RbConfig::CONFIG['host_os'] =~ /linux|freebsd|openbsd|sunos|solaris/) and (not `which notify-send`.empty?)
33
- true
34
- else
35
- ::Guard::UI.error 'The :notifysend notifier runs only on Linux, FreeBSD, OpenBSD and Solaris with the libnotify-bin package installed.' unless silent
36
- false
37
- end
23
+ def self.supported_hosts
24
+ %w[linux freebsd openbsd sunos solaris]
25
+ end
26
+
27
+ def self.available?(opts = {})
28
+ super
29
+ _register!(opts)
38
30
  end
39
31
 
40
- # Show a system notification.
32
+ # Shows a system notification.
41
33
  #
42
- # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
43
- # @param [String] title the notification title
44
34
  # @param [String] message the notification message body
45
- # @param [String] image the path to the notification image
46
- # @param [Hash] options additional notification library options
47
- # @option options [String] c the notification category
48
- # @option options [Number] t the number of milliseconds to display (1000, 3000)
35
+ # @param [Hash] opts additional notification library options
36
+ # @option opts [String] type the notification type. Either 'success',
37
+ # 'pending', 'failed' or 'notify'
38
+ # @option opts [String] title the notification title
39
+ # @option opts [String] image the path to the notification image
40
+ # @option opts [String] c the notification category
41
+ # @option opts [Number] t the number of milliseconds to display (1000,
42
+ # 3000)
49
43
  #
50
- def notify(type, title, message, image, options = { })
44
+ def notify(message, opts = {})
45
+ normalize_standard_options!(opts)
46
+
51
47
  command = [title, message]
52
- options = DEFAULTS.merge(options).merge({
53
- :i => image
54
- })
55
- options[:u] ||= notifysend_urgency(type)
56
- system('notify-send', *to_arguments(command, SUPPORTED, options))
48
+ opts = DEFAULTS.merge(
49
+ i: opts.delete(:image),
50
+ u: _notifysend_urgency(opts.delete(:type))
51
+ ).merge(opts)
52
+
53
+ system('notify-send', *_to_arguments(command, SUPPORTED, opts))
57
54
  end
58
55
 
59
56
  private
60
57
 
61
- # Convert Guards notification type to the best matching
58
+ # Converts Guards notification type to the best matching
62
59
  # notify-send urgency.
63
60
  #
64
61
  # @param [String] type the Guard notification type
65
62
  # @return [String] the notify-send urgency
66
63
  #
67
- def notifysend_urgency(type)
64
+ def _notifysend_urgency(type)
68
65
  { 'failed' => 'normal', 'pending' => 'low' }.fetch(type, 'low')
69
66
  end
70
67
 
71
- # Build a shell command out of a command string and option hash.
68
+ # Builds a shell command out of a command string and option hash.
72
69
  #
73
70
  # @param [String] command the command execute
74
71
  # @param [Array] supported list of supported option flags
75
72
  # @param [Hash] options additional command options
76
73
  # @return [Array<String>] the command and its options converted to a shell command.
77
74
  #
78
- def to_arguments(command, supported, options = {})
75
+ def _to_arguments(command, supported, options = {})
79
76
  options.reduce(command) do |cmd, (flag, value)|
80
77
  supported.include?(flag) ? (cmd << "-#{ flag }" << value.to_s) : cmd
81
78
  end
82
79
  end
80
+
81
+ # @private
82
+ #
83
+ # @return [Boolean] whether or not the notify-send binary is available
84
+ #
85
+ def self._notifysend_binary_available?
86
+ !`which notify-send`.empty?
87
+ end
88
+
89
+ # @private
90
+ #
91
+ def self._register!(options)
92
+ unless _notifysend_binary_available?
93
+ unless options[:silent]
94
+ ::Guard::UI.error 'The :notifysend notifier runs only on Linux, FreeBSD, OpenBSD and Solaris with the libnotify-bin package installed.'
95
+ end
96
+ false
97
+ end
98
+
99
+ true
100
+ end
101
+
83
102
  end
103
+
84
104
  end
85
105
  end
@@ -1,10 +1,10 @@
1
- require 'rbconfig'
2
- require 'guard/ui'
1
+ require 'guard/notifiers/base'
3
2
 
4
3
  module Guard
5
4
  module Notifier
6
5
 
7
- # System notifications using the [rb-notifu](https://github.com/stereobooster/rb-notifu) gem.
6
+ # System notifications using the
7
+ # [rb-notifu](https://github.com/stereobooster/rb-notifu) gem.
8
8
  #
9
9
  # This gem is available for Windows and sends system notifications to
10
10
  # [Notifu](http://www.paralint.com/projects/notifu/index.html):
@@ -18,80 +18,80 @@ module Guard
18
18
  # notification :notifu
19
19
  #
20
20
  # @example Add the `:notifu` notifier with configuration options to your `Guardfile`
21
- # notification :notifu, :time => 5, :nosound => true, :xp => true
21
+ # notification :notifu, time: 5, nosound: true, xp: true
22
22
  #
23
- module Notifu
24
- extend self
23
+ class Notifu < Base
25
24
 
26
- # Default options for rb-notifu gem
25
+ # Default options for the rb-notifu notifications.
27
26
  DEFAULTS = {
28
- :time => 3,
29
- :icon => false,
30
- :baloon => false,
31
- :nosound => false,
32
- :noquiet => false,
33
- :xp => false
27
+ time: 3,
28
+ icon: false,
29
+ baloon: false,
30
+ nosound: false,
31
+ noquiet: false,
32
+ xp: false
34
33
  }
35
34
 
36
- # Test if the notification library is available.
37
- #
38
- # @param [Boolean] silent true if no error messages should be shown
39
- # @param [Hash] options notifier options
40
- # @return [Boolean] the availability status
41
- #
42
- def available?(silent = false, options = {})
43
- if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
44
- require 'rb-notifu'
45
-
46
- true
35
+ def self.supported_hosts
36
+ %w[mswin mingw]
37
+ end
47
38
 
48
- else
49
- ::Guard::UI.error 'The :notifu notifier runs only on Windows.' unless silent
50
- false
51
- end
39
+ def self.gem_name
40
+ 'rb-notifu'
41
+ end
52
42
 
53
- rescue LoadError
54
- ::Guard::UI.error "Please add \"gem 'rb-notifu'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
55
- false
43
+ def self.available?(opts = {})
44
+ super
45
+ require_gem_safely(opts)
56
46
  end
57
47
 
58
- # Show a system notification.
48
+ # Shows a system notification.
59
49
  #
60
- # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
61
- # @param [String] title the notification title
62
50
  # @param [String] message the notification message body
63
- # @param [String] image the path to the notification image
64
- # @param [Hash] options additional notification library options
65
- # @option options [Number] time the number of seconds to display (0 for infinit)
66
- # @option options [Boolean] icon specify an icon to use ("parent" uses the icon of the parent process)
67
- # @option options [Boolean] baloon enable ballon tips in the registry (for this user only)
68
- # @option options [Boolean] nosound do not play a sound when the tooltip is displayed
69
- # @option options [Boolean] noquiet show the tooltip even if the user is in the quiet period that follows his very first login (Windows 7 and up)
70
- # @option options [Boolean] xp use IUserNotification interface event when IUserNotification2 is available
51
+ # @param [Hash] opts additional notification library options
52
+ # @option opts [String] type the notification type. Either 'success',
53
+ # 'pending', 'failed' or 'notify'
54
+ # @option opts [String] title the notification title
55
+ # @option opts [String] image the path to the notification image
56
+ # @option opts [Number] time the number of seconds to display (0 for
57
+ # infinit)
58
+ # @option opts [Boolean] icon specify an icon to use ("parent" uses the
59
+ # icon of the parent process)
60
+ # @option opts [Boolean] baloon enable ballon tips in the registry (for
61
+ # this user only)
62
+ # @option opts [Boolean] nosound do not play a sound when the tooltip is
63
+ # displayed
64
+ # @option opts [Boolean] noquiet show the tooltip even if the user is in
65
+ # the quiet period that follows his very first login (Windows 7 and up)
66
+ # @option opts [Boolean] xp use IUserNotification interface event when
67
+ # IUserNotification2 is available
71
68
  #
72
- def notify(type, title, message, image, options = { })
73
- require 'rb-notifu'
69
+ def notify(message, opts = {})
70
+ self.class.require_gem_safely
71
+ normalize_standard_options!(opts)
72
+
73
+ opts = DEFAULTS.merge(
74
+ type: _notifu_type(opts.delete(:type)),
75
+ message: message
76
+ ).merge(opts)
74
77
 
75
- ::Notifu.show(DEFAULTS.merge(options).merge({
76
- :type => notifu_type(type),
77
- :title => title,
78
- :message => message
79
- }))
78
+ # The empty block is needed until https://github.com/stereobooster/rb-notifu/pull/1 is merged
79
+ ::Notifu.show(opts) {}
80
80
  end
81
81
 
82
82
  private
83
83
 
84
- # Convert Guards notification type to the best matching
84
+ # Converts Guards notification type to the best matching
85
85
  # Notifu type.
86
86
  #
87
87
  # @param [String] type the Guard notification type
88
88
  # @return [Symbol] the Notify notification type
89
89
  #
90
- def notifu_type(type)
91
- case type
92
- when 'failed'
90
+ def _notifu_type(type)
91
+ case type.to_sym
92
+ when :failed
93
93
  :error
94
- when 'pending'
94
+ when :pending
95
95
  :warn
96
96
  else
97
97
  :info