guard 1.4.0 → 2.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +1 -677
- data/LICENSE +4 -2
- data/README.md +91 -753
- data/bin/_guard-core +11 -0
- data/bin/guard +108 -3
- data/lib/guard/aruba_adapter.rb +59 -0
- data/lib/guard/cli/environments/bundler.rb +22 -0
- data/lib/guard/cli/environments/evaluate_only.rb +35 -0
- data/lib/guard/cli/environments/valid.rb +69 -0
- data/lib/guard/cli.rb +129 -128
- data/lib/guard/commander.rb +104 -0
- data/lib/guard/commands/all.rb +37 -0
- data/lib/guard/commands/change.rb +31 -0
- data/lib/guard/commands/notification.rb +26 -0
- data/lib/guard/commands/pause.rb +29 -0
- data/lib/guard/commands/reload.rb +36 -0
- data/lib/guard/commands/scope.rb +38 -0
- data/lib/guard/commands/show.rb +24 -0
- data/lib/guard/config.rb +18 -0
- data/lib/guard/deprecated/dsl.rb +45 -0
- data/lib/guard/deprecated/evaluator.rb +39 -0
- data/lib/guard/deprecated/guard.rb +328 -0
- data/lib/guard/deprecated/guardfile.rb +84 -0
- data/lib/guard/deprecated/watcher.rb +27 -0
- data/lib/guard/dsl.rb +332 -363
- data/lib/guard/dsl_describer.rb +132 -122
- data/lib/guard/dsl_reader.rb +51 -0
- data/lib/guard/group.rb +34 -14
- data/lib/guard/guardfile/evaluator.rb +232 -0
- data/lib/guard/guardfile/generator.rb +128 -0
- data/lib/guard/guardfile.rb +24 -60
- data/lib/guard/interactor.rb +31 -255
- data/lib/guard/internals/debugging.rb +68 -0
- data/lib/guard/internals/groups.rb +40 -0
- data/lib/guard/internals/helpers.rb +13 -0
- data/lib/guard/internals/plugins.rb +53 -0
- data/lib/guard/internals/queue.rb +51 -0
- data/lib/guard/internals/scope.rb +121 -0
- data/lib/guard/internals/session.rb +180 -0
- data/lib/guard/internals/state.rb +25 -0
- data/lib/guard/internals/tracing.rb +33 -0
- data/lib/guard/internals/traps.rb +10 -0
- data/lib/guard/jobs/base.rb +21 -0
- data/lib/guard/jobs/pry_wrapper.rb +336 -0
- data/lib/guard/jobs/sleep.rb +26 -0
- data/lib/guard/notifier.rb +46 -212
- data/lib/guard/options.rb +22 -0
- data/lib/guard/plugin.rb +303 -0
- data/lib/guard/plugin_util.rb +191 -0
- data/lib/guard/rake_task.rb +42 -0
- data/lib/guard/runner.rb +80 -140
- data/lib/guard/templates/Guardfile +14 -0
- data/lib/guard/terminal.rb +13 -0
- data/lib/guard/ui/colors.rb +56 -0
- data/lib/guard/ui/config.rb +70 -0
- data/lib/guard/ui/logger.rb +30 -0
- data/lib/guard/ui.rb +163 -128
- data/lib/guard/version.rb +1 -2
- data/lib/guard/watcher/pattern/deprecated_regexp.rb +45 -0
- data/lib/guard/watcher/pattern/match_result.rb +18 -0
- data/lib/guard/watcher/pattern/matcher.rb +33 -0
- data/lib/guard/watcher/pattern/pathname_path.rb +15 -0
- data/lib/guard/watcher/pattern/simple_path.rb +23 -0
- data/lib/guard/watcher/pattern.rb +24 -0
- data/lib/guard/watcher.rb +52 -95
- data/lib/guard.rb +108 -376
- data/lib/tasks/releaser.rb +116 -0
- data/man/guard.1 +12 -9
- data/man/guard.1.html +18 -12
- metadata +148 -77
- data/images/guard.png +0 -0
- data/lib/guard/guard.rb +0 -156
- data/lib/guard/hook.rb +0 -120
- data/lib/guard/interactors/coolline.rb +0 -64
- data/lib/guard/interactors/helpers/completion.rb +0 -32
- data/lib/guard/interactors/helpers/terminal.rb +0 -46
- data/lib/guard/interactors/readline.rb +0 -94
- data/lib/guard/interactors/simple.rb +0 -19
- data/lib/guard/notifiers/emacs.rb +0 -69
- data/lib/guard/notifiers/gntp.rb +0 -118
- data/lib/guard/notifiers/growl.rb +0 -99
- data/lib/guard/notifiers/growl_notify.rb +0 -92
- data/lib/guard/notifiers/libnotify.rb +0 -96
- data/lib/guard/notifiers/notifysend.rb +0 -84
- data/lib/guard/notifiers/rb_notifu.rb +0 -102
- data/lib/guard/notifiers/terminal_notifier.rb +0 -66
- data/lib/guard/notifiers/tmux.rb +0 -69
- data/lib/guard/version.rbc +0 -130
data/lib/guard/hook.rb
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
module Guard
|
2
|
-
|
3
|
-
# Guard has a hook mechanism that allows you to insert callbacks for individual Guard plugins.
|
4
|
-
# By default, each of the Guard plugin instance methods has a "_begin" and an "_end" hook.
|
5
|
-
# For example, the Guard::Guard#start method has a :start_begin hook that is runs immediately
|
6
|
-
# before Guard::Guard#start, and a :start_end hook that runs immediately after Guard::Guard#start.
|
7
|
-
#
|
8
|
-
# Read more about [hooks and callbacks on the wiki](https://github.com/guard/guard/wiki/Hooks-and-callbacks).
|
9
|
-
#
|
10
|
-
module Hook
|
11
|
-
|
12
|
-
require 'guard/ui'
|
13
|
-
|
14
|
-
# The Hook module gets included.
|
15
|
-
#
|
16
|
-
# @param [Class] base the class that includes the module
|
17
|
-
#
|
18
|
-
def self.included(base)
|
19
|
-
base.send :include, InstanceMethods
|
20
|
-
end
|
21
|
-
|
22
|
-
# Instance methods that gets included in the base class.
|
23
|
-
#
|
24
|
-
module InstanceMethods
|
25
|
-
|
26
|
-
# When event is a Symbol, {#hook} will generate a hook name
|
27
|
-
# by concatenating the method name from where {#hook} is called
|
28
|
-
# with the given Symbol.
|
29
|
-
#
|
30
|
-
# @example Add a hook with a Symbol
|
31
|
-
#
|
32
|
-
# def run_all
|
33
|
-
# hook :foo
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
# Here, when {Guard::Guard#run_all} is called, {#hook} will notify callbacks
|
37
|
-
# registered for the "run_all_foo" event.
|
38
|
-
#
|
39
|
-
# When event is a String, {#hook} will directly turn the String
|
40
|
-
# into a Symbol.
|
41
|
-
#
|
42
|
-
# @example Add a hook with a String
|
43
|
-
#
|
44
|
-
# def run_all
|
45
|
-
# hook "foo_bar"
|
46
|
-
# end
|
47
|
-
#
|
48
|
-
# When {Guard::Guard#run_all} is called, {#hook} will notify callbacks
|
49
|
-
# registered for the "foo_bar" event.
|
50
|
-
#
|
51
|
-
# @param [Symbol, String] event the name of the Guard event
|
52
|
-
# @param [Array] args the parameters are passed as is to the callbacks registered for the given event.
|
53
|
-
#
|
54
|
-
def hook(event, *args)
|
55
|
-
hook_name = if event.is_a? Symbol
|
56
|
-
calling_method = caller[0][/`([^']*)'/, 1]
|
57
|
-
"#{ calling_method }_#{ event }"
|
58
|
-
else
|
59
|
-
event
|
60
|
-
end.to_sym
|
61
|
-
|
62
|
-
::Guard::UI.debug "Hook :#{ hook_name } executed for #{ self.class }"
|
63
|
-
|
64
|
-
Hook.notify(self.class, hook_name, *args)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
class << self
|
69
|
-
|
70
|
-
# Get all callbacks.
|
71
|
-
#
|
72
|
-
def callbacks
|
73
|
-
@callbacks ||= Hash.new { |hash, key| hash[key] = [] }
|
74
|
-
end
|
75
|
-
|
76
|
-
# Add a callback.
|
77
|
-
#
|
78
|
-
# @param [Block] listener the listener to notify
|
79
|
-
# @param [Guard::Guard] guard_class the Guard class to add the callback
|
80
|
-
# @param [Array<Symbol>] events the events to register
|
81
|
-
#
|
82
|
-
def add_callback(listener, guard_class, events)
|
83
|
-
_events = events.is_a?(Array) ? events : [events]
|
84
|
-
_events.each do |event|
|
85
|
-
callbacks[[guard_class, event]] << listener
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# Checks if a callback has been registered.
|
90
|
-
#
|
91
|
-
# @param [Block] listener the listener to notify
|
92
|
-
# @param [Guard::Guard] guard_class the Guard class to add the callback
|
93
|
-
# @param [Symbol] event the event to look for
|
94
|
-
#
|
95
|
-
def has_callback?(listener, guard_class, event)
|
96
|
-
callbacks[[guard_class, event]].include?(listener)
|
97
|
-
end
|
98
|
-
|
99
|
-
# Notify a callback.
|
100
|
-
#
|
101
|
-
# @param [Guard::Guard] guard_class the Guard class to add the callback
|
102
|
-
# @param [Symbol] event the event to trigger
|
103
|
-
# @param [Array] args the arguments for the listener
|
104
|
-
#
|
105
|
-
def notify(guard_class, event, *args)
|
106
|
-
callbacks[[guard_class, event]].each do |listener|
|
107
|
-
listener.call(guard_class, event, *args)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
# Reset all callbacks.
|
112
|
-
#
|
113
|
-
def reset_callbacks!
|
114
|
-
@callbacks = nil
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|
120
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'guard'
|
2
|
-
require 'guard/ui'
|
3
|
-
require 'guard/interactor'
|
4
|
-
require 'guard/interactors/helpers/terminal'
|
5
|
-
require 'guard/interactors/helpers/completion'
|
6
|
-
|
7
|
-
module Guard
|
8
|
-
|
9
|
-
# Interactor that uses coolline for getting the user input.
|
10
|
-
# This enables history support and auto-completion,
|
11
|
-
#
|
12
|
-
class CoollineInteractor < ::Guard::Interactor
|
13
|
-
include ::Guard::CompletionHelper
|
14
|
-
include ::Guard::TerminalHelper
|
15
|
-
|
16
|
-
# Test if the Interactor is
|
17
|
-
# available in the current environment?
|
18
|
-
#
|
19
|
-
# @param [Boolean] silent true if no error messages should be shown
|
20
|
-
# @return [Boolean] the availability status
|
21
|
-
#
|
22
|
-
def self.available?(silent = false)
|
23
|
-
if RbConfig::CONFIG['RUBY_PROGRAM_VERSION'] == '1.9.3'
|
24
|
-
require 'coolline'
|
25
|
-
true
|
26
|
-
else
|
27
|
-
::Guard::UI.error 'The :coolline interactor runs only on Ruby 1.9.3.' unless silent
|
28
|
-
false
|
29
|
-
end
|
30
|
-
|
31
|
-
rescue LoadError => e
|
32
|
-
::Guard::UI.error "Please add \"gem 'coolline'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
|
33
|
-
false
|
34
|
-
end
|
35
|
-
|
36
|
-
# Read a line from stdin with Readline.
|
37
|
-
#
|
38
|
-
def read_line
|
39
|
-
coolline = Coolline.new do |cool|
|
40
|
-
cool.transform_proc = proc do
|
41
|
-
cool.line
|
42
|
-
end
|
43
|
-
|
44
|
-
cool.completion_proc = proc do
|
45
|
-
word = cool.completed_word
|
46
|
-
auto_complete(word)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
while line = coolline.readline(prompt)
|
51
|
-
process_input(line)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# The current interactor prompt
|
56
|
-
#
|
57
|
-
# @return [String] the prompt to show
|
58
|
-
#
|
59
|
-
def prompt
|
60
|
-
::Guard.listener.paused? ? 'p> ' : '>> '
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'guard'
|
2
|
-
|
3
|
-
module Guard
|
4
|
-
|
5
|
-
# Module for providing word completion to an interactor.
|
6
|
-
#
|
7
|
-
module CompletionHelper
|
8
|
-
|
9
|
-
COMPLETION_ACTIONS = %w[help reload exit pause notification show]
|
10
|
-
|
11
|
-
# Auto complete the given word.
|
12
|
-
#
|
13
|
-
# @param [String] word the partial word
|
14
|
-
# @return [Array<String>] the matching words
|
15
|
-
#
|
16
|
-
def auto_complete(word)
|
17
|
-
completion_list.grep(/^#{ Regexp.escape(word) }/)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Get the auto completion list.
|
21
|
-
#
|
22
|
-
# @return [Array<String>] the list of words
|
23
|
-
#
|
24
|
-
def completion_list
|
25
|
-
groups = ::Guard.groups.map { |group| group.name.to_s }
|
26
|
-
guards = ::Guard.guards.map { |guard| guard.class.to_s.downcase.sub('guard::', '') }
|
27
|
-
|
28
|
-
COMPLETION_ACTIONS + groups + guards - ['default']
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Guard
|
2
|
-
|
3
|
-
# Module for resetting terminal options for an interactor.
|
4
|
-
#
|
5
|
-
module TerminalHelper
|
6
|
-
|
7
|
-
# Start the interactor.
|
8
|
-
#
|
9
|
-
def start
|
10
|
-
store_terminal_settings if stty_exists?
|
11
|
-
super
|
12
|
-
end
|
13
|
-
|
14
|
-
# Stop the interactor.
|
15
|
-
#
|
16
|
-
def stop
|
17
|
-
super
|
18
|
-
restore_terminal_settings if stty_exists?
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
# Detects whether or not the stty command exists
|
24
|
-
# on the user machine.
|
25
|
-
#
|
26
|
-
# @return [Boolean] the status of stty
|
27
|
-
#
|
28
|
-
def stty_exists?
|
29
|
-
@stty_exists ||= system('hash', 'stty')
|
30
|
-
end
|
31
|
-
|
32
|
-
# Stores the terminal settings so we can resore them
|
33
|
-
# when stopping.
|
34
|
-
#
|
35
|
-
def store_terminal_settings
|
36
|
-
@stty_save = `stty -g 2>/dev/null`.chomp
|
37
|
-
end
|
38
|
-
|
39
|
-
# Restore terminal settings
|
40
|
-
#
|
41
|
-
def restore_terminal_settings
|
42
|
-
system("stty #{ @stty_save } 2>/dev/null") if @stty_save
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'guard'
|
2
|
-
require 'guard/ui'
|
3
|
-
require 'guard/interactor'
|
4
|
-
require 'guard/interactors/helpers/terminal'
|
5
|
-
require 'guard/interactors/helpers/completion'
|
6
|
-
|
7
|
-
module Guard
|
8
|
-
|
9
|
-
# Interactor that used readline for getting the user input.
|
10
|
-
# This enables history support and auto-completion, but is
|
11
|
-
# broken on OS X without installing `rb-readline` or using JRuby.
|
12
|
-
#
|
13
|
-
# @see http://bugs.ruby-lang.org/issues/5539
|
14
|
-
#
|
15
|
-
class ReadlineInteractor < ::Guard::Interactor
|
16
|
-
include ::Guard::CompletionHelper
|
17
|
-
include ::Guard::TerminalHelper
|
18
|
-
|
19
|
-
# Test if the Interactor is
|
20
|
-
# available in the current environment?
|
21
|
-
#
|
22
|
-
# @param [Boolean] silent true if no error messages should be shown
|
23
|
-
# @return [Boolean] the availability status
|
24
|
-
#
|
25
|
-
def self.available?(silent = false)
|
26
|
-
require 'readline'
|
27
|
-
|
28
|
-
if defined?(RbReadline) || defined?(JRUBY_VERSION) || RbConfig::CONFIG['target_os'] =~ /linux/i
|
29
|
-
true
|
30
|
-
else
|
31
|
-
::Guard::UI.error 'The :readline interactor runs only fine on JRuby, Linux or with the gem \'rb-readline\' installed.' unless silent
|
32
|
-
false
|
33
|
-
end
|
34
|
-
|
35
|
-
rescue LoadError => e
|
36
|
-
::Guard::UI.error "Please install Ruby Readline support or add \"gem 'rb-readline'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
|
37
|
-
false
|
38
|
-
end
|
39
|
-
|
40
|
-
# Initialize the interactor.
|
41
|
-
#
|
42
|
-
def initialize
|
43
|
-
require 'readline'
|
44
|
-
|
45
|
-
Readline.completion_proc = proc { |word| auto_complete(word) }
|
46
|
-
|
47
|
-
begin
|
48
|
-
Readline.completion_append_character = ' '
|
49
|
-
rescue NotImplementedError
|
50
|
-
# Ignore, we just don't support it then
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Stop the interactor.
|
55
|
-
#
|
56
|
-
def stop
|
57
|
-
# Erase the current line for Ruby Readline
|
58
|
-
if Readline.respond_to?(:refresh_line) && !defined?(::JRUBY_VERSION)
|
59
|
-
Readline.refresh_line
|
60
|
-
end
|
61
|
-
|
62
|
-
# Erase the current line for Rb-Readline
|
63
|
-
if defined?(RbReadline) && RbReadline.rl_outstream
|
64
|
-
RbReadline._rl_erase_entire_line
|
65
|
-
end
|
66
|
-
|
67
|
-
super
|
68
|
-
end
|
69
|
-
|
70
|
-
# Read a line from stdin with Readline.
|
71
|
-
#
|
72
|
-
def read_line
|
73
|
-
require 'readline'
|
74
|
-
|
75
|
-
while line = Readline.readline(prompt, true)
|
76
|
-
line.gsub!(/^\W*/, '')
|
77
|
-
if line =~ /^\s*$/ or Readline::HISTORY.to_a[-2] == line
|
78
|
-
Readline::HISTORY.pop
|
79
|
-
end
|
80
|
-
|
81
|
-
process_input(line)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# The current interactor prompt
|
86
|
-
#
|
87
|
-
# @return [String] the prompt to show
|
88
|
-
#
|
89
|
-
def prompt
|
90
|
-
::Guard.listener.paused? ? 'p> ' : '> '
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'guard/interactor'
|
2
|
-
|
3
|
-
module Guard
|
4
|
-
|
5
|
-
# Simple interactor that that reads user
|
6
|
-
# input from standard input.
|
7
|
-
#
|
8
|
-
class SimpleInteractor < ::Guard::Interactor
|
9
|
-
|
10
|
-
# Read a line from stdin with Readline.
|
11
|
-
#
|
12
|
-
def read_line
|
13
|
-
while line = $stdin.gets
|
14
|
-
process_input(line.gsub(/^\W*/, '').chomp)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
|
3
|
-
module Guard
|
4
|
-
module Notifier
|
5
|
-
|
6
|
-
# Default options for EmacsClient
|
7
|
-
DEFAULTS = {
|
8
|
-
:client => 'emacsclient',
|
9
|
-
:success => 'ForestGreen',
|
10
|
-
:failed => 'Firebrick',
|
11
|
-
:default => 'Black',
|
12
|
-
}
|
13
|
-
|
14
|
-
# Send a notification to Emacs with emacsclient (http://www.emacswiki.org/emacs/EmacsClient).
|
15
|
-
#
|
16
|
-
# @example Add the `:emacs` notifier to your `Guardfile`
|
17
|
-
# notification :emacs
|
18
|
-
#
|
19
|
-
module Emacs
|
20
|
-
extend self
|
21
|
-
|
22
|
-
# Test if Emacs with running server is available.
|
23
|
-
#
|
24
|
-
# @param [Boolean] silent true if no error messages should be shown
|
25
|
-
# @return [Boolean] the availability status
|
26
|
-
#
|
27
|
-
def available?(silent = false)
|
28
|
-
result = `#{ DEFAULTS[:client] } --eval '1' 2> /dev/null || echo 'N/A'`
|
29
|
-
|
30
|
-
if result.chomp! == 'N/A'
|
31
|
-
false
|
32
|
-
else
|
33
|
-
true
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Show a system notification.
|
38
|
-
#
|
39
|
-
# @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
|
40
|
-
# @param [String] title the notification title
|
41
|
-
# @param [String] message the notification message body
|
42
|
-
# @param [String] image the path to the notification image
|
43
|
-
# @param [Hash] options additional notification library options
|
44
|
-
# @option options [Boolean] sticky make the notification sticky
|
45
|
-
# @option options [String, Integer] priority specify an int or named key (default is 0)
|
46
|
-
#
|
47
|
-
def notify(type, title, message, image, options = { })
|
48
|
-
system(%(#{ DEFAULTS[:client] } --eval "(set-face-background 'modeline \\"#{ emacs_color(type) }\\")"))
|
49
|
-
end
|
50
|
-
|
51
|
-
# Get the Emacs color for the notification type.
|
52
|
-
# You can configure your own color by overwrite the defaults.
|
53
|
-
#
|
54
|
-
# @param [String] type the notification type
|
55
|
-
# @return [String] the name of the emacs color
|
56
|
-
#
|
57
|
-
def emacs_color(type)
|
58
|
-
case type
|
59
|
-
when 'success'
|
60
|
-
DEFAULTS[:success]
|
61
|
-
when 'failed'
|
62
|
-
DEFAULTS[:failed]
|
63
|
-
else
|
64
|
-
DEFAULTS[:default]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/lib/guard/notifiers/gntp.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
require 'guard/ui'
|
3
|
-
|
4
|
-
module Guard
|
5
|
-
module Notifier
|
6
|
-
|
7
|
-
# System notifications using the [ruby_gntp](https://github.com/snaka/ruby_gntp) gem.
|
8
|
-
#
|
9
|
-
# This gem is available for OS X, Linux and Windows and sends system notifications to
|
10
|
-
# the following system notification frameworks through the
|
11
|
-
# [Growl Network Transport Protocol](http://www.growlforwindows.com/gfw/help/gntp.aspx):
|
12
|
-
#
|
13
|
-
# * [Growl](http://growl.info)
|
14
|
-
# * [Growl for Windows](http://www.growlforwindows.com)
|
15
|
-
# * [Growl for Linux](http://mattn.github.com/growl-for-linux)
|
16
|
-
# * [Snarl](https://sites.google.com/site/snarlapp/)
|
17
|
-
#
|
18
|
-
# @example Add the `ruby_gntp` gem to your `Gemfile`
|
19
|
-
# group :development
|
20
|
-
# gem 'ruby_gntp'
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# @example Add the `:gntp` notifier to your `Guardfile`
|
24
|
-
# notification :gntp
|
25
|
-
#
|
26
|
-
# @example Add the `:gntp` notifier with configuration options to your `Guardfile`
|
27
|
-
# notification :gntp, :sticky => true, :host => '192.168.1.5', :password => 'secret'
|
28
|
-
#
|
29
|
-
module GNTP
|
30
|
-
extend self
|
31
|
-
|
32
|
-
# Default options for the ruby gtnp gem
|
33
|
-
DEFAULTS = {
|
34
|
-
:sticky => false,
|
35
|
-
:host => '127.0.0.1',
|
36
|
-
:password => '',
|
37
|
-
:port => 23053
|
38
|
-
}
|
39
|
-
|
40
|
-
# Is this notifier already registered
|
41
|
-
#
|
42
|
-
# @return [Boolean] registration status
|
43
|
-
#
|
44
|
-
def registered?
|
45
|
-
@registered ||= false
|
46
|
-
end
|
47
|
-
|
48
|
-
# Mark the notifier as registered.
|
49
|
-
#
|
50
|
-
def registered!
|
51
|
-
@registered = true
|
52
|
-
end
|
53
|
-
|
54
|
-
# Test if the notification library is available.
|
55
|
-
#
|
56
|
-
# @param [Boolean] silent true if no error messages should be shown
|
57
|
-
# @return [Boolean] the availability status
|
58
|
-
#
|
59
|
-
def available?(silent = false)
|
60
|
-
if RbConfig::CONFIG['host_os'] =~ /darwin|linux|freebsd|openbsd|sunos|solaris|mswin|mingw/
|
61
|
-
require 'ruby_gntp'
|
62
|
-
true
|
63
|
-
|
64
|
-
else
|
65
|
-
::Guard::UI.error 'The :gntp notifier runs only on Mac OS X, Linux, FreeBSD, OpenBSD, Solaris and Windows.' unless silent
|
66
|
-
false
|
67
|
-
end
|
68
|
-
|
69
|
-
rescue LoadError
|
70
|
-
::Guard::UI.error "Please add \"gem 'ruby_gntp'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
|
71
|
-
false
|
72
|
-
end
|
73
|
-
|
74
|
-
# Show a system notification.
|
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 [String] host the hostname or IP address to which to send a remote notification
|
82
|
-
# @option options [String] password the password used for remote notifications
|
83
|
-
# @option options [Integer] port the port to send a remote notification
|
84
|
-
# @option options [Boolean] sticky make the notification sticky
|
85
|
-
#
|
86
|
-
def notify(type, title, message, image, options = { })
|
87
|
-
require 'ruby_gntp'
|
88
|
-
|
89
|
-
options = DEFAULTS.merge(options)
|
90
|
-
|
91
|
-
gntp = ::GNTP.new('Guard', options.delete(:host), options.delete(:password), options.delete(:port))
|
92
|
-
|
93
|
-
unless registered?
|
94
|
-
gntp.register({
|
95
|
-
:app_icon => File.expand_path(File.join(__FILE__, '..', '..', '..', '..', 'images', 'guard.png')),
|
96
|
-
:notifications => [
|
97
|
-
{ :name => 'notify', :enabled => true },
|
98
|
-
{ :name => 'failed', :enabled => true },
|
99
|
-
{ :name => 'pending', :enabled => true },
|
100
|
-
{ :name => 'success', :enabled => true }
|
101
|
-
]
|
102
|
-
})
|
103
|
-
|
104
|
-
registered!
|
105
|
-
end
|
106
|
-
|
107
|
-
gntp.notify(options.merge({
|
108
|
-
:name => type,
|
109
|
-
:title => title,
|
110
|
-
:text => message,
|
111
|
-
:icon => image
|
112
|
-
}))
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
@@ -1,99 +0,0 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
require 'guard/ui'
|
3
|
-
|
4
|
-
module Guard
|
5
|
-
module Notifier
|
6
|
-
|
7
|
-
# System notifications using the [growl](https://github.com/visionmedia/growl) gem.
|
8
|
-
#
|
9
|
-
# This gem is available for OS X and sends system notifications to
|
10
|
-
# [Growl](http://growl.info) through the [GrowlNotify](http://growl.info/downloads)
|
11
|
-
# executable.
|
12
|
-
#
|
13
|
-
# The `growlnotify` executable must be installed manually or by using
|
14
|
-
# [Homebrew](http://mxcl.github.com/homebrew/).
|
15
|
-
#
|
16
|
-
# Sending notifications with this notifier will not show the different
|
17
|
-
# Guard notifications in the Growl preferences. Use the :gntp or :growl_notify
|
18
|
-
# notifiers if you want to customize each notification type in Growl.
|
19
|
-
#
|
20
|
-
# @example Install `growlnotify` with Homebrew
|
21
|
-
# brew install growlnotify
|
22
|
-
#
|
23
|
-
# @example Add the `growl` gem to your `Gemfile`
|
24
|
-
# group :development
|
25
|
-
# gem 'growl'
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# @example Add the `:growl` notifier to your `Guardfile`
|
29
|
-
# notification :growl
|
30
|
-
#
|
31
|
-
# @example Add the `:growl_notify` notifier with configuration options to your `Guardfile`
|
32
|
-
# notification :growl, :sticky => true, :host => '192.168.1.5', :password => 'secret'
|
33
|
-
#
|
34
|
-
module Growl
|
35
|
-
extend self
|
36
|
-
|
37
|
-
# Default options for growl gem
|
38
|
-
DEFAULTS = {
|
39
|
-
:sticky => false,
|
40
|
-
:priority => 0
|
41
|
-
}
|
42
|
-
|
43
|
-
# Test if the notification library is available.
|
44
|
-
#
|
45
|
-
# @param [Boolean] silent true if no error messages should be shown
|
46
|
-
# @return [Boolean] the availability status
|
47
|
-
#
|
48
|
-
def available?(silent = false)
|
49
|
-
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
50
|
-
require 'growl'
|
51
|
-
|
52
|
-
if ::Growl.installed?
|
53
|
-
true
|
54
|
-
else
|
55
|
-
::Guard::UI.error "Please install the 'growlnotify' executable." unless silent
|
56
|
-
false
|
57
|
-
end
|
58
|
-
|
59
|
-
else
|
60
|
-
::Guard::UI.error 'The :growl notifier runs only on Mac OS X.' unless silent
|
61
|
-
false
|
62
|
-
end
|
63
|
-
|
64
|
-
rescue LoadError, NameError
|
65
|
-
::Guard::UI.error "Please add \"gem 'growl'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
|
66
|
-
false
|
67
|
-
end
|
68
|
-
|
69
|
-
# Show a system notification.
|
70
|
-
#
|
71
|
-
# The documented options are for GrowlNotify 1.3, but the older options are
|
72
|
-
# also supported. Please see `growlnotify --help`.
|
73
|
-
#
|
74
|
-
# Priority can be one of the following named keys: `Very Low`, `Moderate`, `Normal`,
|
75
|
-
# `High`, `Emergency`. It can also be an int between -2 and 2.
|
76
|
-
#
|
77
|
-
# @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
|
78
|
-
# @param [String] title the notification title
|
79
|
-
# @param [String] message the notification message body
|
80
|
-
# @param [String] image the path to the notification image
|
81
|
-
# @param [Hash] options additional notification library options
|
82
|
-
# @option options [Boolean] sticky make the notification sticky
|
83
|
-
# @option options [String, Integer] priority specify an int or named key (default is 0)
|
84
|
-
# @option options [String] host the hostname or IP address to which to send a remote notification
|
85
|
-
# @option options [String] password the password used for remote notifications
|
86
|
-
#
|
87
|
-
def notify(type, title, message, image, options = { })
|
88
|
-
require 'growl'
|
89
|
-
|
90
|
-
::Growl.notify(message, DEFAULTS.merge(options).merge({
|
91
|
-
:name => 'Guard',
|
92
|
-
:title => title,
|
93
|
-
:image => image
|
94
|
-
}))
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|