guard 1.8.3 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
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,12 +1,14 @@
1
- require 'guard/ui'
1
+ require 'guard/notifiers/base'
2
2
 
3
3
  module Guard
4
4
  module Notifier
5
5
 
6
- # System notifications using the [terminal-notifier-guard](https://github.com/Springest/terminal-notifier-guard gem.
6
+ # System notifications using the
7
+ # [terminal-notifier-guard](https://github.com/Springest/terminal-notifier-guard)
8
+ # gem.
7
9
  #
8
- # This gem is available for OS X 10.8 Mountain Lion and sends notifications to the OS X
9
- # notification center.
10
+ # This gem is available for OS X 10.8 Mountain Lion and sends notifications
11
+ # to the OS X notification center.
10
12
  #
11
13
  # @example Add the `terminal-notifier-guard` gem to your `Gemfile`
12
14
  # group :development
@@ -19,49 +21,59 @@ module Guard
19
21
  # @example Add the `:terminal_notifier` notifier with configuration options to your `Guardfile`
20
22
  # notification :terminal_notifier, app_name: "MyApp"
21
23
  #
22
- module TerminalNotifier
23
- extend self
24
+ class TerminalNotifier < Base
24
25
 
25
- # Test if the notification library is available.
26
+ def self.supported_hosts
27
+ %w[darwin]
28
+ end
29
+
30
+ def self.gem_name
31
+ 'terminal-notifier-guard'
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.
26
40
  #
27
- # @param [Boolean] silent true if no error messages should be shown
28
- # @param [Hash] options notifier options
29
- # @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 (ignored)
47
+ # @option opts [String] app_name name of your app
48
+ # @option opts [String] execute a command
49
+ # @option opts [String] activate an app bundle
50
+ # @option opts [String] open some url or file
30
51
  #
31
- def available?(silent = false, options = {})
32
- require 'terminal-notifier-guard'
52
+ def notify(message, opts = {})
53
+ self.class.require_gem_safely
54
+ title = opts[:title]
55
+ normalize_standard_options!(opts)
33
56
 
57
+ opts.delete(:image)
58
+ opts[:title] = title || [opts.delete(:app_name) { 'Guard' }, opts[:type].downcase.capitalize].join(' ')
59
+
60
+ ::TerminalNotifier::Guard.execute(false, opts.merge(message: message))
61
+ end
62
+
63
+ # @private
64
+ #
65
+ def self._register!(options)
34
66
  if ::TerminalNotifier::Guard.available?
35
67
  true
36
68
  else
37
- ::Guard::UI.error 'The :terminal_notifier only runs on Mac OS X 10.8 and later.' unless silent
69
+ unless options[:silent]
70
+ ::Guard::UI.error 'The :terminal_notifier only runs on Mac OS X 10.8 and later.'
71
+ end
38
72
  false
39
73
  end
40
-
41
- rescue LoadError, NameError
42
- ::Guard::UI.error "Please add \"gem 'terminal-notifier-guard'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
43
- false
44
74
  end
45
75
 
46
- # Show a system notification.
47
- #
48
- # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
49
- # @param [String] title the notification title
50
- # @param [String] message the notification message body
51
- # @param [String] image the path to the notification image (ignored)
52
- # @param [Hash] options additional notification library options
53
- # @option options [String] app_name name of your app
54
- # @option options [String] execute a command
55
- # @option options [String] activate an app bundle
56
- # @option options [String] open some url or file
57
- #
58
- def notify(type, title, message, image, options = { })
59
- require 'terminal-notifier-guard'
60
- options[:title] = title || [options[:app_name] || 'Guard', type.downcase.capitalize].join(' ')
61
- options.merge!(:type => type.to_sym, :message => message)
62
- options.delete :app_name if options[:app_name]
63
- ::TerminalNotifier::Guard.execute(false, options)
64
- end
65
76
  end
77
+
66
78
  end
67
79
  end
@@ -1,31 +1,35 @@
1
- # Module for notifying test result to terminal title
1
+ require 'guard/notifiers/base'
2
+
2
3
  module Guard
3
4
  module Notifier
4
- module TerminalTitle
5
- extend self
6
5
 
7
- # Test if the notification library is available.
6
+ # Shows system notifications in the terminal title bar.
7
+ #
8
+ class TerminalTitle < Base
9
+
10
+ # Shows a system notification.
8
11
  #
9
- # @param [Boolean] silent true if no error messages should be shown
10
- # @param [Hash] options notifier options
11
- # @return [Boolean] the availability status
12
+ # @param [Hash] opts additional notification library options
13
+ # @option opts [String] message the notification message body
14
+ # @option opts [String] type the notification type. Either 'success',
15
+ # 'pending', 'failed' or 'notify'
16
+ # @option opts [String] title the notification title
12
17
  #
13
- def available?(silent = false, options = {})
14
- true
18
+ def notify(message, opts = {})
19
+ normalize_standard_options!(opts)
20
+
21
+ first_line = message.sub(/^\n/, '').sub(/\n.*/m, '')
22
+
23
+ puts "\e]2;[#{ opts[:title] }] #{ first_line }\a"
15
24
  end
16
25
 
17
- # Show a system notification.
26
+ # Clears the terminal title
18
27
  #
19
- # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
20
- # @param [String] title the notification title
21
- # @param [String] message the notification message body
22
- # @param [String] image the path to the notification image
23
- # @param [Hash] options additional notification library options
24
- #
25
- def notify(type, title, message, image, options = { })
26
- first_line = message.sub(/^\n/, '').sub(/\n.*/m, '')
27
- puts("\e]2;[#{ title }] #{ first_line }\a")
28
+ def self.turn_off
29
+ puts "\e]2;\a"
28
30
  end
31
+
29
32
  end
33
+
30
34
  end
31
35
  end
@@ -1,3 +1,5 @@
1
+ require 'guard/notifiers/base'
2
+
1
3
  module Guard
2
4
  module Notifier
3
5
 
@@ -8,100 +10,118 @@ module Guard
8
10
  # notification :tmux
9
11
  #
10
12
  # @example Enable text messages
11
- # notification :tmux, :display_message => true
13
+ # notification :tmux, display_message: true
12
14
  #
13
15
  # @example Customize the tmux status colored for notifications
14
- # notification :tmux, :color_location => 'status-right-bg'
16
+ # notification :tmux, color_location: 'status-right-bg'
15
17
  #
16
- module Tmux
17
- extend self
18
+ class Tmux < Base
18
19
 
19
- # Default options for Tmux
20
+ # Default options for the tmux notifications.
20
21
  DEFAULTS = {
21
- :client => 'tmux',
22
- :tmux_environment => 'TMUX',
23
- :success => 'green',
24
- :failed => 'red',
25
- :pending => 'yellow',
26
- :default => 'green',
27
- :timeout => 5,
28
- :display_message => false,
29
- :default_message_format => '%s - %s',
30
- :default_message_color => 'white',
31
- :line_separator => ' - ',
32
- :color_location => 'status-left-bg'
22
+ client: 'tmux',
23
+ tmux_environment: 'TMUX',
24
+ success: 'green',
25
+ failed: 'red',
26
+ pending: 'yellow',
27
+ default: 'green',
28
+ timeout: 5,
29
+ display_message: false,
30
+ default_message_format: '%s - %s',
31
+ default_message_color: 'white',
32
+ line_separator: ' - ',
33
+ color_location: 'status-left-bg'
33
34
  }
34
35
 
35
- # Test if currently running in a Tmux session
36
- #
37
- # @param [Boolean] silent true if no error messages should be shown
38
- # @param [Hash] options notifier options
39
- # @return [Boolean] the availability status
40
- #
41
- def available?(silent = false, options = {})
42
- if ENV[options.fetch(:tmux_environment, DEFAULTS[:tmux_environment])].nil?
43
- ::Guard::UI.error 'The :tmux notifier runs only on when Guard is executed inside of a tmux session.' unless silent
36
+ def self.available?(opts = {})
37
+ super
38
+
39
+ if ENV[opts.fetch(:tmux_environment, DEFAULTS[:tmux_environment])].nil?
40
+ unless opts[:silent]
41
+ ::Guard::UI.error 'The :tmux notifier runs only on when Guard is executed inside of a tmux session.'
42
+ end
44
43
  false
45
44
  else
46
45
  true
47
46
  end
48
47
  end
49
48
 
50
- # Show a system notification. By default, the Tmux notifier only makes use of a color based
51
- # notification, changing the background color of the `color_location` to the color defined
52
- # in either the `success`, `failed`, `pending` or `default`, depending on the notification type.
53
- # If you also want display a text message, you have to enable it explicit by setting `display_message`
54
- # to `true`.
49
+ # Shows a system notification.
50
+ #
51
+ # By default, the Tmux notifier only makes
52
+ # use of a color based notification, changing the background color of the
53
+ # `color_location` to the color defined in either the `success`,
54
+ # `failed`, `pending` or `default`, depending on the notification type.
55
+ # If you also want display a text message, you have to enable it explicit
56
+ # by setting `display_message` to `true`.
55
57
  #
56
- # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
57
58
  # @param [String] title the notification title
58
- # @param [String] message the notification message body
59
- # @param [String] image the path to the notification image
60
- # @param [Hash] options additional notification library options
61
- # @option options [String] color_location the location where to draw the color notification
62
- # @option options [Boolean] display_message whether to display a message or not
59
+ # @param [Hash] opts additional notification library options
60
+ # @option opts [String] type the notification type. Either 'success',
61
+ # 'pending', 'failed' or 'notify'
62
+ # @option opts [String] message the notification message body
63
+ # @option opts [String] image the path to the notification image
64
+ # @option opts [String] color_location the location where to draw the
65
+ # color notification
66
+ # @option opts [Boolean] display_message whether to display a message
67
+ # or not
63
68
  #
64
- def notify(type, title, message, image, options = { })
65
- color = tmux_color(type, options)
66
- color_location = options[:color_location] || DEFAULTS[:color_location]
69
+ def notify(message, opts = {})
70
+ normalize_standard_options!(opts)
71
+ opts.delete(:image)
72
+
73
+ color_location = opts.fetch(:color_location, DEFAULTS[:color_location])
74
+ color = tmux_color(opts[:type], opts)
67
75
 
68
- run_client "set #{ color_location } #{ color }"
76
+ _run_client "set #{ color_location } #{ color }"
69
77
 
70
- show_message = options[:display_message] || DEFAULTS[:display_message]
71
- display_message(type, title, message, options) if show_message
78
+ if opts.fetch(:display_message, DEFAULTS[:display_message])
79
+ display_message(opts.delete(:type).to_s, opts.delete(:title), message, opts)
80
+ end
72
81
  end
73
82
 
74
- # Display a message in the status bar of tmux.
83
+ # Displays a message in the status bar of tmux.
75
84
  #
76
- # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
85
+ # @param [String] type the notification type. Either 'success',
86
+ # 'pending', 'failed' or 'notify'
77
87
  # @param [String] title the notification title
78
88
  # @param [String] message the notification message body
79
89
  # @param [Hash] options additional notification library options
80
- # @option options [Integer] timeout the amount of seconds to show the message in the status bar
81
- # @option options [String] success_message_format a string to use as formatter for the success message.
82
- # @option options [String] failed_message_format a string to use as formatter for the failed message.
83
- # @option options [String] pending_message_format a string to use as formatter for the pending message.
84
- # @option options [String] default_message_format a string to use as formatter when no format per type is defined.
85
- # @option options [String] success_message_color the success notification foreground color name.
86
- # @option options [String] failed_message_color the failed notification foreground color name.
87
- # @option options [String] pending_message_color the pending notification foreground color name.
88
- # @option options [String] default_message_color a notification foreground color to use when no color per type is defined.
89
- # @option options [String] line_separator a string to use instead of a line-break.
90
+ # @option options [Integer] timeout the amount of seconds to show the
91
+ # message in the status bar
92
+ # @option options [String] success_message_format a string to use as
93
+ # formatter for the success message.
94
+ # @option options [String] failed_message_format a string to use as
95
+ # formatter for the failed message.
96
+ # @option options [String] pending_message_format a string to use as
97
+ # formatter for the pending message.
98
+ # @option options [String] default_message_format a string to use as
99
+ # formatter when no format per type is defined.
100
+ # @option options [String] success_message_color the success notification
101
+ # foreground color name.
102
+ # @option options [String] failed_message_color the failed notification
103
+ # foreground color name.
104
+ # @option options [String] pending_message_color the pending notification
105
+ # foreground color name.
106
+ # @option options [String] default_message_color a notification
107
+ # foreground color to use when no color per type is defined.
108
+ # @option options [String] line_separator a string to use instead of a
109
+ # line-break.
90
110
  #
91
- def display_message(type, title, message, options = { })
92
- message_format = options["#{ type }_message_format".to_sym] || options[:default_message_format] || DEFAULTS[:default_message_format]
93
- message_color = options["#{ type }_message_color".to_sym] || options[:default_message_color] || DEFAULTS[:default_message_color]
94
- display_time = options[:timeout] || DEFAULTS[:timeout]
95
- separator = options[:line_separator] || DEFAULTS[:line_separator]
96
-
97
- color = tmux_color type, options
98
- formatted_message = message.split("\n").join(separator)
99
- display_message = message_format % [title, formatted_message]
100
-
101
- run_client "set display-time #{ display_time * 1000 }"
102
- run_client "set message-fg #{ message_color }"
103
- run_client "set message-bg #{ color }"
104
- run_client "display-message '#{ display_message }'"
111
+ def display_message(type, title, message, opts = {})
112
+ message_format = opts.fetch("#{ type }_message_format".to_sym, opts.fetch(:default_message_format, DEFAULTS[:default_message_format]))
113
+ message_color = opts.fetch("#{ type }_message_color".to_sym, opts.fetch(:default_message_color, DEFAULTS[:default_message_color]))
114
+ display_time = opts.fetch(:timeout, DEFAULTS[:timeout])
115
+ separator = opts.fetch(:line_separator, DEFAULTS[:line_separator])
116
+
117
+ color = tmux_color type, opts
118
+ formatted_message = message.split("\n").join(separator)
119
+ display_message = message_format % [title, formatted_message]
120
+
121
+ _run_client "set display-time #{ display_time * 1000 }"
122
+ _run_client "set message-fg #{ message_color }"
123
+ _run_client "set message-bg #{ color }"
124
+ _run_client "display-message '#{ display_message }'"
105
125
  end
106
126
 
107
127
  # Get the Tmux color for the notification type.
@@ -110,55 +130,51 @@ module Guard
110
130
  # @param [String] type the notification type
111
131
  # @return [String] the name of the emacs color
112
132
  #
113
- def tmux_color(type, options = { })
114
- case type
115
- when 'success'
116
- options[:success] || DEFAULTS[:success]
117
- when 'failed'
118
- options[:failed] || DEFAULTS[:failed]
119
- when 'pending'
120
- options[:pending] || DEFAULTS[:pending]
121
- else
122
- options[:default] || DEFAULTS[:default]
123
- end
133
+ def tmux_color(type, opts = {})
134
+ type = type.to_sym
135
+ type = :default unless [:success, :failed, :pending].include?(type)
136
+
137
+ opts.fetch(type, DEFAULTS[type])
124
138
  end
125
139
 
126
140
  # Notification starting, save the current Tmux settings
127
141
  # and quiet the Tmux output.
128
142
  #
129
- def turn_on(options = { })
143
+ def turn_on
130
144
  unless @options_stored
131
- reset_options_store
132
-
145
+ _reset_options_store
133
146
  `#{ DEFAULTS[:client] } show`.each_line do |line|
134
147
  option, _, setting = line.chomp.partition(' ')
135
- @options_store[option] = setting
148
+ options_store[option] = setting
136
149
  end
137
150
 
138
151
  @options_stored = true
139
152
  end
140
153
 
141
- run_client "set quiet on"
154
+ _run_client 'set quiet on'
142
155
  end
143
156
 
144
157
  # Notification stopping. Restore the previous Tmux state
145
158
  # if available (existing options are restored, new options
146
159
  # are unset) and unquiet the Tmux output.
147
160
  #
148
- def turn_off(options = { })
161
+ def turn_off
149
162
  if @options_stored
150
163
  @options_store.each do |key, value|
151
164
  if value
152
- run_client "set #{ key } #{ value }"
165
+ _run_client "set #{ key } #{ value }"
153
166
  else
154
- run_client "set -u #{ key }"
167
+ _run_client "set -u #{ key }"
155
168
  end
156
169
  end
157
-
158
- reset_options_store
170
+ _reset_options_store
159
171
  end
160
172
 
161
- run_client 'set quiet off'
173
+ _run_client 'set quiet off'
174
+ end
175
+
176
+ def options_store
177
+ @options_store ||= {}
162
178
  end
163
179
 
164
180
  private
@@ -168,13 +184,13 @@ module Guard
168
184
  super
169
185
  end
170
186
 
171
- def run_client(args)
187
+ def _run_client(args)
172
188
  system("#{ DEFAULTS[:client] } #{args}")
173
189
  end
174
190
 
175
191
  # Reset the internal Tmux options store defaults.
176
192
  #
177
- def reset_options_store
193
+ def _reset_options_store
178
194
  @options_stored = false
179
195
  @options_store = {
180
196
  'status-left-bg' => nil,
@@ -188,5 +204,6 @@ module Guard
188
204
  end
189
205
 
190
206
  end
207
+
191
208
  end
192
209
  end