guard 0.8.8 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/CHANGELOG.md +16 -1
  2. data/README.md +665 -293
  3. data/bin/fsevent_watch_guard +0 -0
  4. data/lib/guard.rb +66 -31
  5. data/lib/guard/cli.rb +9 -3
  6. data/lib/guard/dsl.rb +32 -5
  7. data/lib/guard/dsl_describer.rb +3 -2
  8. data/lib/guard/guard.rb +2 -2
  9. data/lib/guard/interactor.rb +179 -48
  10. data/lib/guard/listener.rb +32 -17
  11. data/lib/guard/listeners/darwin.rb +5 -9
  12. data/lib/guard/listeners/linux.rb +6 -10
  13. data/lib/guard/listeners/windows.rb +4 -2
  14. data/lib/guard/notifier.rb +171 -258
  15. data/lib/guard/notifiers/gntp.rb +114 -0
  16. data/lib/guard/notifiers/growl.rb +98 -0
  17. data/lib/guard/notifiers/growl_notify.rb +91 -0
  18. data/lib/guard/notifiers/libnotify.rb +96 -0
  19. data/lib/guard/notifiers/rb_notifu.rb +101 -0
  20. data/lib/guard/ui.rb +2 -2
  21. data/lib/guard/version.rb +1 -1
  22. data/lib/guard/watcher.rb +1 -1
  23. data/lib/vendor/darwin/Gemfile +6 -0
  24. data/lib/vendor/darwin/Guardfile +8 -0
  25. data/lib/vendor/darwin/LICENSE +20 -0
  26. data/lib/vendor/darwin/README.rdoc +254 -0
  27. data/lib/vendor/darwin/Rakefile +21 -0
  28. data/lib/vendor/darwin/ext/extconf.rb +61 -0
  29. data/lib/vendor/darwin/ext/fsevent/fsevent_watch.c +226 -0
  30. data/lib/vendor/darwin/lib/rb-fsevent.rb +2 -0
  31. data/lib/vendor/darwin/lib/rb-fsevent/fsevent.rb +105 -0
  32. data/lib/vendor/darwin/lib/rb-fsevent/version.rb +3 -0
  33. data/lib/vendor/darwin/rb-fsevent.gemspec +24 -0
  34. data/lib/vendor/darwin/spec/fixtures/folder1/file1.txt +0 -0
  35. data/lib/vendor/darwin/spec/fixtures/folder1/folder2/file2.txt +0 -0
  36. data/lib/vendor/darwin/spec/rb-fsevent/fsevent_spec.rb +75 -0
  37. data/lib/vendor/darwin/spec/spec_helper.rb +24 -0
  38. data/lib/vendor/linux/MIT-LICENSE +20 -0
  39. data/lib/vendor/linux/README.md +66 -0
  40. data/lib/vendor/linux/Rakefile +54 -0
  41. data/lib/vendor/linux/VERSION +1 -0
  42. data/lib/vendor/linux/lib/rb-inotify.rb +17 -0
  43. data/lib/vendor/linux/lib/rb-inotify/event.rb +139 -0
  44. data/lib/vendor/linux/lib/rb-inotify/native.rb +31 -0
  45. data/lib/vendor/linux/lib/rb-inotify/native/flags.rb +89 -0
  46. data/lib/vendor/linux/lib/rb-inotify/notifier.rb +308 -0
  47. data/lib/vendor/linux/lib/rb-inotify/watcher.rb +83 -0
  48. data/lib/vendor/linux/rb-inotify.gemspec +53 -0
  49. data/lib/vendor/windows/Gemfile +4 -0
  50. data/lib/vendor/windows/README.md +34 -0
  51. data/lib/vendor/windows/Rakefile +18 -0
  52. data/lib/vendor/windows/lib/rb-fchange.rb +14 -0
  53. data/lib/vendor/windows/lib/rb-fchange/event.rb +29 -0
  54. data/lib/vendor/windows/lib/rb-fchange/native.rb +45 -0
  55. data/lib/vendor/windows/lib/rb-fchange/native/flags.rb +78 -0
  56. data/lib/vendor/windows/lib/rb-fchange/notifier.rb +149 -0
  57. data/lib/vendor/windows/lib/rb-fchange/version.rb +3 -0
  58. data/lib/vendor/windows/lib/rb-fchange/watcher.rb +99 -0
  59. data/lib/vendor/windows/rb-fchange.gemspec +34 -0
  60. data/lib/vendor/windows/spec/fixtures/folder1/file1.txt +0 -0
  61. data/lib/vendor/windows/spec/fixtures/folder1/folder2/file2.txt +0 -0
  62. data/lib/vendor/windows/spec/rb-fchange/fchange_spec.rb +119 -0
  63. data/lib/vendor/windows/spec/spec_helper.rb +21 -0
  64. metadata +87 -22
  65. data/lib/guard/version.rbc +0 -180
@@ -0,0 +1,114 @@
1
+ require 'rbconfig'
2
+
3
+ module Guard
4
+ module Notifier
5
+
6
+ # System notifications using the [ruby_gntp](https://github.com/snaka/ruby_gntp) gem.
7
+ #
8
+ # This gem is available for OS X, Linux and Windows and sends system notifications to
9
+ # the following system notification frameworks through the
10
+ # [Growl Network Transport Protocol](http://www.growlforwindows.com/gfw/help/gntp.aspx):
11
+ #
12
+ # * [Growl](http://growl.info)
13
+ # * [Growl for Windows](http://www.growlforwindows.com)
14
+ # * [Growl for Linux](http://mattn.github.com/growl-for-linux)
15
+ # * [Snarl](https://sites.google.com/site/snarlapp/)
16
+ #
17
+ # @example Add the `ruby_gntp` gem to your `Gemfile`
18
+ # group :development
19
+ # gem 'ruby_gntp'
20
+ # end
21
+ #
22
+ # @example Add the `:gntp` notifier to your `Guardfile`
23
+ # notification :gntp
24
+ #
25
+ # @example Add the `:gntp` notifier with configuration options to your `Guardfile`
26
+ # notification :gntp, :sticky => true, :host => '192.168.1.5', :password => 'secret'
27
+ #
28
+ module GNTP
29
+ extend self
30
+
31
+ # Default options for the ruby gtnp gem
32
+ DEFAULTS = {
33
+ :sticky => false,
34
+ :host => 'localhost',
35
+ :password => '',
36
+ :port => 23053
37
+ }
38
+
39
+ # Is this notifier already registered
40
+ #
41
+ # @return [Boolean] registration status
42
+ #
43
+ def registered?
44
+ @registered ||= false
45
+ end
46
+
47
+ # Mark the notifier as registered.
48
+ #
49
+ def registered!
50
+ @registered = true
51
+ end
52
+
53
+ # Test if the notification library is available.
54
+ #
55
+ # @param [Boolean] silent true if no error messages should be shown
56
+ # @return [Boolean] the availability status
57
+ #
58
+ def available?(silent = false)
59
+ if RbConfig::CONFIG['host_os'] =~ /darwin|linux|freebsd|openbsd|sunos|solaris|mswin|mingw/
60
+ require 'ruby_gntp'
61
+ true
62
+
63
+ else
64
+ ::Guard::UI.error 'The :gntp notifier runs only on Mac OS X, Linux, FreeBSD, OpenBSD, Solaris and Windows.' unless silent
65
+ false
66
+ end
67
+
68
+ rescue LoadError
69
+ ::Guard::UI.error "Please add \"gem 'ruby_gntp'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
70
+ false
71
+ end
72
+
73
+ # Show a system notification.
74
+ #
75
+ # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
76
+ # @param [String] title the notification title
77
+ # @param [String] message the notification message body
78
+ # @param [String] image the path to the notification image
79
+ # @param [Hash] options additional notification library options
80
+ # @option options [String] host the hostname or IP address to which to send a remote notification
81
+ # @option options [String] password the password used for remote notifications
82
+ # @option options [Integer] port the port to send a remote notification
83
+ # @option options [Boolean] sticky make the notification sticky
84
+ #
85
+ def notify(type, title, message, image, options = { })
86
+ require 'ruby_gntp'
87
+
88
+ options = DEFAULTS.merge(options)
89
+
90
+ gntp = ::GNTP.new('Guard', options.delete(:host), options.delete(:password), options.delete(:port))
91
+
92
+ unless registered?
93
+ gntp.register(:notifications => [
94
+ { :name => 'notify', :enabled => true },
95
+ { :name => 'failed', :enabled => true },
96
+ { :name => 'pending', :enabled => true },
97
+ { :name => 'success', :enabled => true }
98
+ ])
99
+
100
+ registered!
101
+ end
102
+
103
+ gntp.notify(options.merge({
104
+ :name => type,
105
+ :title => title,
106
+ :text => message,
107
+ :icon => "file://#{ image }"
108
+ }))
109
+ end
110
+
111
+ end
112
+ end
113
+ end
114
+
@@ -0,0 +1,98 @@
1
+ require 'rbconfig'
2
+
3
+ module Guard
4
+ module Notifier
5
+
6
+ # System notifications using the [growl](https://github.com/visionmedia/growl) gem.
7
+ #
8
+ # This gem is available for OS X and sends system notifications to
9
+ # [Growl](http://growl.info) through the [GrowlNotify](http://growl.info/downloads)
10
+ # executable.
11
+ #
12
+ # The `growlnotify` executable must be installed manually or by using
13
+ # [Homebrew](http://mxcl.github.com/homebrew/).
14
+ #
15
+ # Sending notifications with this notifier will not show the different
16
+ # Guard notifications in the Growl preferences. Use the :gntp or :growl_notify
17
+ # notifiers if you want to customize each notification type in Growl.
18
+ #
19
+ # @example Install `growlnotify` with Homebrew
20
+ # brew install growlnotify
21
+ #
22
+ # @example Add the `growl` gem to your `Gemfile`
23
+ # group :development
24
+ # gem 'growl'
25
+ # end
26
+ #
27
+ # @example Add the `:growl` notifier to your `Guardfile`
28
+ # notification :growl
29
+ #
30
+ # @example Add the `:growl_notify` notifier with configuration options to your `Guardfile`
31
+ # notification :growl, :sticky => true, :host => '192.168.1.5', :password => 'secret'
32
+ #
33
+ module Growl
34
+ extend self
35
+
36
+ # Default options for growl gem
37
+ DEFAULTS = {
38
+ :sticky => false,
39
+ :priority => 0
40
+ }
41
+
42
+ # Test if the notification library is available.
43
+ #
44
+ # @param [Boolean] silent true if no error messages should be shown
45
+ # @return [Boolean] the availability status
46
+ #
47
+ def available?(silent = false)
48
+ if RbConfig::CONFIG['host_os'] =~ /darwin/
49
+ require 'growl'
50
+
51
+ if ::Growl.installed?
52
+ true
53
+ else
54
+ ::Guard::UI.error "Please install the 'growlnotify' executable." unless silent
55
+ false
56
+ end
57
+
58
+ else
59
+ ::Guard::UI.error 'The :growl notifier runs only on Mac OS X.' unless silent
60
+ false
61
+ end
62
+
63
+ rescue LoadError, NameError
64
+ ::Guard::UI.error "Please add \"gem 'growl'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
65
+ false
66
+ end
67
+
68
+ # Show a system notification.
69
+ #
70
+ # The documented options are for GrowlNotify 1.3, but the older options are
71
+ # also supported. Please see `growlnotify --help`.
72
+ #
73
+ # Priority can be one of the following named keys: `Very Low`, `Moderate`, `Normal`,
74
+ # `High`, `Emergency`. It can also be an int between -2 and 2.
75
+ #
76
+ # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
77
+ # @param [String] title the notification title
78
+ # @param [String] message the notification message body
79
+ # @param [String] image the path to the notification image
80
+ # @param [Hash] options additional notification library options
81
+ # @option options [Boolean] sticky make the notification sticky
82
+ # @option options [String, Integer] priority specify an int or named key (default is 0)
83
+ # @option options [String] host the hostname or IP address to which to send a remote notification
84
+ # @option options [String] password the password used for remote notifications
85
+ #
86
+ def notify(type, title, message, image, options = { })
87
+ require 'growl'
88
+
89
+ ::Growl.notify(message, DEFAULTS.merge(options).merge({
90
+ :name => 'Guard',
91
+ :title => title,
92
+ :image => image
93
+ }))
94
+ end
95
+
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,91 @@
1
+ require 'rbconfig'
2
+
3
+ module Guard
4
+ module Notifier
5
+
6
+ # System notifications using the [GrowlNotify](https://github.com/scottdavis/growl_notify) gem.
7
+ #
8
+ # This gem is available for OS X and sends system notifications to
9
+ # [Growl](http://growl.info) through AppleScript.
10
+ #
11
+ # @example Add the `growl_notify` gem to your `Gemfile`
12
+ # group :development
13
+ # gem 'growl_notify'
14
+ # end
15
+ #
16
+ # @example Add the `:growl_notify` notifier to your `Guardfile`
17
+ # notification :growl_notify
18
+ #
19
+ # @example Add the `:growl_notify` notifier with configuration options to your `Guardfile`
20
+ # notification :growl_notify, :sticky => true
21
+ #
22
+ module GrowlNotify
23
+ extend self
24
+
25
+ # Default options for growl_notify gem
26
+ DEFAULTS = {
27
+ :sticky => false,
28
+ :priority => 0
29
+ }
30
+
31
+ # Test if the notification library is available.
32
+ #
33
+ # @param [Boolean] silent true if no error messages should be shown
34
+ # @return [Boolean] the availability status
35
+ #
36
+ def available?(silent = false)
37
+ if RbConfig::CONFIG['host_os'] =~ /darwin/
38
+ require 'growl_notify'
39
+
40
+ begin
41
+ if ::GrowlNotify.application_name != 'Guard'
42
+ ::GrowlNotify.config do |c|
43
+ c.notifications = ['success', 'pending', 'failed', 'notify']
44
+ c.default_notifications = 'notify'
45
+ c.application_name = 'Guard'
46
+ end
47
+ end
48
+
49
+ true
50
+
51
+ rescue ::GrowlNotify::GrowlNotFound
52
+ ::Guard::UI.error 'Please install Growl from http://growl.info' unless silent
53
+ false
54
+ end
55
+
56
+ else
57
+ ::Guard::UI.error 'The :growl_notify notifier runs only on Mac OS X.' unless silent
58
+ false
59
+ end
60
+
61
+ rescue LoadError
62
+ ::Guard::UI.error "Please add \"gem 'growl_notify'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
63
+ false
64
+ end
65
+
66
+ # Show a system notification.
67
+ #
68
+ # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
69
+ # @param [String] title the notification title
70
+ # @param [String] message the notification message body
71
+ # @param [String] image the path to the notification image
72
+ # @param [Hash] options additional notification library options
73
+ # @option options [Boolean] sticky if the message should stick to the screen
74
+ # @option options [Integer] priority the importance of message from -2 (very low) to 2 (emergency)
75
+ #
76
+ def notify(type, title, message, image, options = { })
77
+ require 'growl_notify'
78
+
79
+ ::GrowlNotify.send_notification(DEFAULTS.merge(options).merge({
80
+ :application_name => 'Guard',
81
+ :with_name => type,
82
+ :title => title,
83
+ :description => message,
84
+ :icon => image
85
+ }))
86
+ end
87
+
88
+ end
89
+ end
90
+ end
91
+
@@ -0,0 +1,96 @@
1
+ require 'rbconfig'
2
+
3
+ module Guard
4
+ module Notifier
5
+
6
+ # System notifications using the [libnotify](https://github.com/splattael/libnotify) gem.
7
+ #
8
+ # This gem is available for Linux, FreeBSD, OpenBSD and Solaris and sends system notifications to
9
+ # Gnome [libnotify](http://developer.gnome.org/libnotify):
10
+ #
11
+ # @example Add the `libnotify` gem to your `Gemfile`
12
+ # group :development
13
+ # gem 'libnotify'
14
+ # end
15
+ #
16
+ # @example Add the `:libnotify` notifier to your `Guardfile`
17
+ # notification :libnotify
18
+ #
19
+ # @example Add the `:libnotify` notifier with configuration options to your `Guardfile`
20
+ # notification :libnotify, :timeout => 5, :transient => true, :append => false
21
+ #
22
+ module Libnotify
23
+ extend self
24
+
25
+ # Default options for libnotify gem
26
+ DEFAULTS = {
27
+ :transient => false,
28
+ :append => true,
29
+ :timeout => 3
30
+ }
31
+
32
+ # Test if the notification library is available.
33
+ #
34
+ # @param [Boolean] silent true if no error messages should be shown
35
+ # @return [Boolean] the availability status
36
+ #
37
+ def available?(silent = false)
38
+ if RbConfig::CONFIG['host_os'] =~ /linux|freebsd|openbsd|sunos|solaris/
39
+ require 'libnotify'
40
+
41
+ true
42
+
43
+ else
44
+ ::Guard::UI.error 'The :libnotify notifier runs only on Linux, FreeBSD, OpenBSD and Solaris.' unless silent
45
+ false
46
+ end
47
+
48
+ rescue LoadError
49
+ ::Guard::UI.error "Please add \"gem 'libnotify'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
50
+ false
51
+ end
52
+
53
+ # Show a system notification.
54
+ #
55
+ # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
56
+ # @param [String] title the notification title
57
+ # @param [String] message the notification message body
58
+ # @param [String] image the path to the notification image
59
+ # @param [Hash] options additional notification library options
60
+ # @option options [Boolean] transient keep the notifications around after display
61
+ # @option options [Boolean] append append onto existing notification
62
+ # @option options [Number, Boolean] timeout the number of seconds to display (1.5 (s), 1000 (ms), false)
63
+ #
64
+ def notify(type, title, message, image, options = { })
65
+ require 'libnotify'
66
+
67
+ ::Libnotify.show(DEFAULTS.merge(options).merge({
68
+ :urgency => libnotify_urgency(type),
69
+ :summary => title,
70
+ :body => message,
71
+ :icon_path => image
72
+ }))
73
+ end
74
+
75
+ private
76
+
77
+ # Convert Guards notification type to the best matching
78
+ # libnotify urgency.
79
+ #
80
+ # @param [String] type the Guard notification type
81
+ # @return [Symbol] the libnotify urgency
82
+ #
83
+ def libnotify_urgency(type)
84
+ case type
85
+ when 'failed'
86
+ :critical
87
+ when 'pending'
88
+ :normal
89
+ else
90
+ :low
91
+ end
92
+ end
93
+
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,101 @@
1
+ require 'rbconfig'
2
+
3
+ module Guard
4
+ module Notifier
5
+
6
+ # System notifications using the [rb-notifu](https://github.com/stereobooster/rb-notifu) gem.
7
+ #
8
+ # This gem is available for Windows and sends system notifications to
9
+ # [Notifu](http://www.paralint.com/projects/notifu/index.html):
10
+ #
11
+ # @example Add the `rb-notifu` gem to your `Gemfile`
12
+ # group :development
13
+ # gem 'rb-notifu'
14
+ # end
15
+ #
16
+ # @example Add the `:notifu` notifier to your `Guardfile`
17
+ # notification :notifu
18
+ #
19
+ # @example Add the `:notifu` notifier with configuration options to your `Guardfile`
20
+ # notification :notifu, :time => 5, :nosound => true, :xp => true
21
+ #
22
+ module Notifu
23
+ extend self
24
+
25
+ # Default options for rb-notifu gem
26
+ DEFAULTS = {
27
+ :time => 3,
28
+ :icon => false,
29
+ :baloon => false,
30
+ :nosound => false,
31
+ :noquiet => false,
32
+ :xp => false
33
+ }
34
+
35
+ # Test if the notification library is available.
36
+ #
37
+ # @param [Boolean] silent true if no error messages should be shown
38
+ # @return [Boolean] the availability status
39
+ #
40
+ def available?(silent = false)
41
+ if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
42
+ require 'rb-notifu'
43
+
44
+ true
45
+
46
+ else
47
+ ::Guard::UI.error 'The :notifu notifier runs only on Windows.' unless silent
48
+ false
49
+ end
50
+
51
+ rescue LoadError
52
+ ::Guard::UI.error "Please add \"gem 'rb-notifu'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
53
+ false
54
+ end
55
+
56
+ # Show a system notification.
57
+ #
58
+ # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
59
+ # @param [String] title the notification title
60
+ # @param [String] message the notification message body
61
+ # @param [String] image the path to the notification image
62
+ # @param [Hash] options additional notification library options
63
+ # @option options [Number] time the number of seconds to display (0 for infinit)
64
+ # @option options [Boolean] icon specify an icon to use ("parent" uses the icon of the parent process)
65
+ # @option options [Boolean] baloon enable ballon tips in the registry (for this user only)
66
+ # @option options [Boolean] nosound do not play a sound when the tooltip is displayed
67
+ # @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)
68
+ # @option options [Boolean] xp use IUserNotification interface event when IUserNotification2 is available
69
+ #
70
+ def notify(type, title, message, image, options = { })
71
+ require 'rb-notifu'
72
+
73
+ ::Notifu.show(DEFAULTS.merge(options).merge({
74
+ :type => notifu_type(type),
75
+ :title => title,
76
+ :message => message
77
+ }))
78
+ end
79
+
80
+ private
81
+
82
+ # Convert Guards notification type to the best matching
83
+ # Notifu type.
84
+ #
85
+ # @param [String] type the Guard notification type
86
+ # @return [Symbol] the Notify notification type
87
+ #
88
+ def notifu_type(type)
89
+ case type
90
+ when 'failed'
91
+ :error
92
+ when 'pending'
93
+ :warn
94
+ else
95
+ :info
96
+ end
97
+ end
98
+
99
+ end
100
+ end
101
+ end