guard 2.10.0 → 2.10.1
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.
- checksums.yaml +4 -4
- data/lib/guard.rb +11 -2
- data/lib/guard.rb.orig +57 -154
- data/lib/guard/dsl.rb +13 -8
- data/lib/guard/dsl.rb.orig +77 -23
- data/lib/guard/internals/session.rb +5 -0
- data/lib/guard/internals/session.rb.orig +15 -2
- data/lib/guard/notifier.rb +5 -6
- data/lib/guard/notifiers/tmux.rb +24 -24
- data/lib/guard/plugin.rb +2 -2
- data/lib/guard/ui.rb +1 -7
- data/lib/guard/version.rb +1 -1
- data/lib/guard/version.rb.orig +1 -1
- metadata +2 -12
- data/lib/guard/cli.rb.orig +0 -220
- data/lib/guard/deprecated/guard.rb.orig +0 -178
- data/lib/guard/dsl_describer.rb.orig +0 -188
- data/lib/guard/notifier.rb.orig +0 -247
- data/lib/guard/notifier/detected.rb.orig +0 -83
- data/lib/guard/plugin.rb.orig +0 -300
- data/lib/guard/reevaluator.rb.orig +0 -22
- data/lib/guard/templates/Guardfile.orig +0 -2
- data/lib/guard/ui.rb.orig +0 -274
- data/lib/guard/watcher.rb.orig +0 -122
@@ -1,178 +0,0 @@
|
|
1
|
-
require "guard/config"
|
2
|
-
fail "Deprecations disabled (strict mode)" if Guard::Config.new.strict?
|
3
|
-
|
4
|
-
require "guard/ui"
|
5
|
-
require "guard/plugin_util"
|
6
|
-
require "guard/guardfile/evaluator"
|
7
|
-
|
8
|
-
module Guard
|
9
|
-
# @deprecated Every method in this module is deprecated
|
10
|
-
module Deprecated
|
11
|
-
module Guard
|
12
|
-
def self.add_deprecated(klass)
|
13
|
-
klass.send(:extend, ClassMethods)
|
14
|
-
end
|
15
|
-
|
16
|
-
module ClassMethods
|
17
|
-
MORE_INFO_ON_UPGRADING_TO_GUARD_2 = <<-EOS.gsub(/^\s*/, "")
|
18
|
-
For more information on how to upgrade for Guard 2.0, please head
|
19
|
-
over to: https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0%s
|
20
|
-
EOS
|
21
|
-
|
22
|
-
# @deprecated Use `Guard.plugins(filter)` instead.
|
23
|
-
#
|
24
|
-
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
|
25
|
-
# upgrade for Guard 2.0
|
26
|
-
#
|
27
|
-
GUARDS = <<-EOS.gsub(/^\s*/, "")
|
28
|
-
Starting with Guard 2.0 'Guard.guards(filter)' is deprecated.
|
29
|
-
|
30
|
-
Please use 'Guard.plugins(filter)' instead.
|
31
|
-
|
32
|
-
#{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#deprecated-methods"}
|
33
|
-
EOS
|
34
|
-
|
35
|
-
def guards(filter = nil)
|
36
|
-
::Guard::UI.deprecation(GUARDS)
|
37
|
-
plugins(filter)
|
38
|
-
end
|
39
|
-
|
40
|
-
# @deprecated Use `Guard.add_plugin(name, options = {})` instead.
|
41
|
-
#
|
42
|
-
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
|
43
|
-
# upgrade for Guard 2.0
|
44
|
-
#
|
45
|
-
ADD_GUARD = <<-EOS.gsub(/^\s*/, "")
|
46
|
-
Starting with Guard 2.0 'Guard.add_guard(name, options = {})' is
|
47
|
-
deprecated.
|
48
|
-
|
49
|
-
Please use 'Guard.add_plugin(name, options = {})' instead.
|
50
|
-
|
51
|
-
#{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#deprecated-methods"}
|
52
|
-
EOS
|
53
|
-
|
54
|
-
def add_guard(*args)
|
55
|
-
::Guard::UI.deprecation(ADD_GUARD)
|
56
|
-
add_plugin(*args)
|
57
|
-
end
|
58
|
-
|
59
|
-
# @deprecated Use
|
60
|
-
# `Guard::PluginUtil.new(name).plugin_class(fail_gracefully:
|
61
|
-
# fail_gracefully)` instead.
|
62
|
-
#
|
63
|
-
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
|
64
|
-
# upgrade for Guard 2.0
|
65
|
-
#
|
66
|
-
GET_GUARD_CLASS = <<-EOS.gsub(/^\s*/, "")
|
67
|
-
Starting with Guard 2.0 'Guard.get_guard_class(name, fail_gracefully
|
68
|
-
= false)' is deprecated and is now always on.
|
69
|
-
|
70
|
-
Please use 'Guard::PluginUtil.new(name).plugin_class(fail_gracefully:
|
71
|
-
fail_gracefully)' instead.
|
72
|
-
|
73
|
-
#{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#deprecated-methods"}
|
74
|
-
EOS
|
75
|
-
|
76
|
-
def get_guard_class(name, fail_gracefully = false)
|
77
|
-
UI.deprecation(GET_GUARD_CLASS)
|
78
|
-
PluginUtil.new(name).plugin_class(fail_gracefully: fail_gracefully)
|
79
|
-
end
|
80
|
-
|
81
|
-
# @deprecated Use `Guard::PluginUtil.new(name).plugin_location` instead.
|
82
|
-
#
|
83
|
-
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
|
84
|
-
# upgrade for Guard 2.0
|
85
|
-
#
|
86
|
-
LOCATE_GUARD = <<-EOS.gsub(/^\s*/, "")
|
87
|
-
Starting with Guard 2.0 'Guard.locate_guard(name)' is deprecated.
|
88
|
-
|
89
|
-
Please use 'Guard::PluginUtil.new(name).plugin_location' instead.
|
90
|
-
|
91
|
-
#{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#deprecated-methods"}
|
92
|
-
EOS
|
93
|
-
|
94
|
-
def locate_guard(name)
|
95
|
-
UI.deprecation(LOCATE_GUARD)
|
96
|
-
PluginUtil.new(name).plugin_location
|
97
|
-
end
|
98
|
-
|
99
|
-
# @deprecated Use `Guard::PluginUtil.plugin_names` instead.
|
100
|
-
#
|
101
|
-
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
|
102
|
-
# upgrade for Guard 2.0
|
103
|
-
#
|
104
|
-
# Deprecator message for the `Guard.guard_gem_names` method
|
105
|
-
GUARD_GEM_NAMES = <<-EOS.gsub(/^\s*/, "")
|
106
|
-
Starting with Guard 2.0 'Guard.guard_gem_names' is deprecated.
|
107
|
-
|
108
|
-
Please use 'Guard::PluginUtil.plugin_names' instead.
|
109
|
-
|
110
|
-
#{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % "#deprecated-methods"}
|
111
|
-
EOS
|
112
|
-
|
113
|
-
def guard_gem_names
|
114
|
-
UI.deprecation(GUARD_GEM_NAMES)
|
115
|
-
PluginUtil.plugin_names
|
116
|
-
end
|
117
|
-
|
118
|
-
RUNNING = <<-EOS.gsub(/^\s*/, "")
|
119
|
-
Starting with Guard 2.7.1 it was discovered that Guard.running was
|
120
|
-
never initialized or used internally.
|
121
|
-
EOS
|
122
|
-
|
123
|
-
def running
|
124
|
-
UI.deprecation(RUNNING)
|
125
|
-
nil
|
126
|
-
end
|
127
|
-
|
128
|
-
LOCK = <<-EOS.gsub(/^\s*/, "")
|
129
|
-
Starting with Guard 2.7.1 it was discovered that this accessor was
|
130
|
-
never initialized or used internally.
|
131
|
-
EOS
|
132
|
-
def lock
|
133
|
-
UI.deprecation(LOCK)
|
134
|
-
end
|
135
|
-
|
136
|
-
EVALUATOR = <<-EOS.gsub(/^\s*/, "")
|
137
|
-
Starting with Guard 2.8.2 this method shouldn't be used
|
138
|
-
EOS
|
139
|
-
|
140
|
-
def evaluator
|
141
|
-
UI.deprecation(EVALUATOR)
|
142
|
-
options = ::Guard.state.session.evaluator_options
|
143
|
-
::Guard::Guardfile::Evaluator.new(options)
|
144
|
-
end
|
145
|
-
|
146
|
-
RESET_EVALUATOR = <<-EOS.gsub(/^\s*/, "")
|
147
|
-
Starting with Guard 2.8.2 this method shouldn't be used
|
148
|
-
EOS
|
149
|
-
|
150
|
-
def reset_evaluator(_options)
|
151
|
-
UI.deprecation(RESET_EVALUATOR)
|
152
|
-
end
|
153
|
-
|
154
|
-
RUNNER = <<-EOS.gsub(/^\s*/, "")
|
155
|
-
Starting with Guard 2.8.2 this method shouldn't be used
|
156
|
-
EOS
|
157
|
-
|
158
|
-
def runner
|
159
|
-
UI.deprecation(RUNNER)
|
160
|
-
::Guard::Runner.new
|
161
|
-
end
|
162
|
-
|
163
|
-
EVALUATE_GUARDFILE = <<-EOS.gsub(/^\s*/, "")
|
164
|
-
Starting with Guard 2.8.2 this method shouldn't be used
|
165
|
-
EOS
|
166
|
-
|
167
|
-
def evaluate_guardfile
|
168
|
-
UI.deprecation(EVALUATE_GUARDFILE)
|
169
|
-
options = ::Guard.state.session.evaluator_options
|
170
|
-
evaluator = ::Guard::Guardfile::Evaluator.new(options)
|
171
|
-
evaluator.evaluate
|
172
|
-
msg = "No plugins found in Guardfile, please add at least one."
|
173
|
-
::Guard::UI.error msg if _pluginless_guardfile?
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
@@ -1,188 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "formatador"
|
3
|
-
|
4
|
-
require "guard/guardfile/evaluator"
|
5
|
-
require "guard/ui"
|
6
|
-
require "guard/metadata"
|
7
|
-
|
8
|
-
module Guard
|
9
|
-
# The DslDescriber evaluates the Guardfile and creates an internal structure
|
10
|
-
# of it that is used in some inspection utility methods like the CLI commands
|
11
|
-
# `show` and `list`.
|
12
|
-
#
|
13
|
-
# @see Guard::Dsl
|
14
|
-
# @see Guard::CLI
|
15
|
-
#
|
16
|
-
class DslDescriber
|
17
|
-
# Initializes a new DslDescriber object.
|
18
|
-
#
|
19
|
-
# @option options [String] guardfile the path to a valid Guardfile
|
20
|
-
#
|
21
|
-
# @option options [String] guardfile_contents a string representing the
|
22
|
-
# content of a valid Guardfile
|
23
|
-
#
|
24
|
-
# @see Guard::Guardfile::Evaluator#initialize
|
25
|
-
#
|
26
|
-
def initialize(options = {})
|
27
|
-
::Guard.reset_groups
|
28
|
-
::Guard.reset_plugins
|
29
|
-
::Guard.reset_scope
|
30
|
-
::Guard.reset_options(options)
|
31
|
-
end
|
32
|
-
|
33
|
-
# List the Guard plugins that are available for use in your system and marks
|
34
|
-
# those that are currently used in your `Guardfile`.
|
35
|
-
#
|
36
|
-
# @see CLI#list
|
37
|
-
#
|
38
|
-
def list
|
39
|
-
_evaluate_guardfile
|
40
|
-
names = ::Guard::PluginUtil.plugin_names.sort.uniq
|
41
|
-
final_rows = names.inject([]) do |rows, name|
|
42
|
-
used = ::Guard.plugins(name).any?
|
43
|
-
rows << {
|
44
|
-
Plugin: name.capitalize,
|
45
|
-
Guardfile: used ? "✔" : "✘"
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
Formatador.display_compact_table(final_rows, [:Plugin, :Guardfile])
|
50
|
-
end
|
51
|
-
|
52
|
-
# Shows all Guard plugins and their options that are defined in
|
53
|
-
# the `Guardfile`.
|
54
|
-
#
|
55
|
-
# @see CLI#show
|
56
|
-
#
|
57
|
-
def show
|
58
|
-
_evaluate_guardfile
|
59
|
-
groups = ::Guard.groups
|
60
|
-
|
61
|
-
final_rows = groups.each_with_object([]) do |group, rows|
|
62
|
-
|
63
|
-
plugins = Array(::Guard.plugins(group: group.name))
|
64
|
-
|
65
|
-
plugins.each do |plugin|
|
66
|
-
options = plugin.options.inject({}) do |o, (k, v)|
|
67
|
-
o.tap { |option| option[k.to_s] = v }
|
68
|
-
end.sort
|
69
|
-
|
70
|
-
if options.empty?
|
71
|
-
rows << :split
|
72
|
-
rows << {
|
73
|
-
Group: group.title,
|
74
|
-
Plugin: plugin.title,
|
75
|
-
Option: "",
|
76
|
-
Value: ""
|
77
|
-
}
|
78
|
-
else
|
79
|
-
options.each_with_index do |(option, value), index|
|
80
|
-
if index == 0
|
81
|
-
rows << :split
|
82
|
-
rows << {
|
83
|
-
Group: group.title,
|
84
|
-
Plugin: plugin.title,
|
85
|
-
Option: option.to_s,
|
86
|
-
Value: value.inspect
|
87
|
-
}
|
88
|
-
else
|
89
|
-
rows << {
|
90
|
-
Group: "",
|
91
|
-
Plugin: "",
|
92
|
-
Option: option.to_s,
|
93
|
-
Value: value.inspect
|
94
|
-
}
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
rows
|
101
|
-
end
|
102
|
-
|
103
|
-
Formatador.display_compact_table(
|
104
|
-
final_rows.drop(1),
|
105
|
-
[:Group, :Plugin, :Option, :Value]
|
106
|
-
)
|
107
|
-
end
|
108
|
-
|
109
|
-
# Shows all notifiers and their options that are defined in
|
110
|
-
# the `Guardfile`.
|
111
|
-
#
|
112
|
-
# @see CLI#show
|
113
|
-
#
|
114
|
-
def notifiers
|
115
|
-
_evaluate_guardfile
|
116
|
-
|
117
|
-
supported = ::Guard::Notifier::SUPPORTED
|
118
|
-
Notifier.connect
|
119
|
-
detected = Notifier.notifiers
|
120
|
-
Notifier.disconnect
|
121
|
-
|
122
|
-
merged_notifiers = supported.inject(:merge)
|
123
|
-
final_rows = merged_notifiers.each_with_object([]) do |definition, rows|
|
124
|
-
|
125
|
-
name = definition[0]
|
126
|
-
clazz = definition[1]
|
127
|
-
available = clazz.available?(silent: true) ? "✔" : "✘"
|
128
|
-
notifier = detected.detect { |n| n[:name] == name }
|
129
|
-
used = notifier ? "✔" : "✘"
|
130
|
-
|
131
|
-
options = _merge_options(clazz, notifier)
|
132
|
-
options.delete(:silent)
|
133
|
-
|
134
|
-
if options.empty?
|
135
|
-
rows << :split
|
136
|
-
_add_row(rows, name, available, used, "", "")
|
137
|
-
else
|
138
|
-
options.each_with_index do |(option, value), index|
|
139
|
-
if index == 0
|
140
|
-
rows << :split
|
141
|
-
_add_row(rows, name, available, used, option.to_s, value.inspect)
|
142
|
-
else
|
143
|
-
_add_row(rows, "", "", "", option.to_s, value.inspect)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
rows
|
149
|
-
end
|
150
|
-
|
151
|
-
Formatador.display_compact_table(
|
152
|
-
final_rows.drop(1),
|
153
|
-
[:Name, :Available, :Used, :Option, :Value]
|
154
|
-
)
|
155
|
-
end
|
156
|
-
|
157
|
-
private
|
158
|
-
|
159
|
-
# Evaluates the `Guardfile` by delegating to
|
160
|
-
# {Guard::Guardfile::Evaluator#evaluate_guardfile}.
|
161
|
-
#
|
162
|
-
def _evaluate_guardfile
|
163
|
-
::Guard.save_scope
|
164
|
-
::Guard::Guardfile::Evaluator.new(::Guard.options).evaluate_guardfile
|
165
|
-
::Guard.restore_scope
|
166
|
-
end
|
167
|
-
|
168
|
-
def _merge_options(klass, notifier)
|
169
|
-
notify_options = notifier ? notifier[:options] : {}
|
170
|
-
|
171
|
-
if klass.const_defined?(:DEFAULTS)
|
172
|
-
klass.const_get(:DEFAULTS).merge(notify_options)
|
173
|
-
else
|
174
|
-
notify_options
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def _add_row(rows, name, available, used, option, value)
|
179
|
-
rows << {
|
180
|
-
Name: name,
|
181
|
-
Available: available,
|
182
|
-
Used: used,
|
183
|
-
Option: option,
|
184
|
-
Value: value
|
185
|
-
}
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
data/lib/guard/notifier.rb.orig
DELETED
@@ -1,247 +0,0 @@
|
|
1
|
-
require "yaml"
|
2
|
-
require "rbconfig"
|
3
|
-
require "pathname"
|
4
|
-
|
5
|
-
require_relative "internals/environment"
|
6
|
-
require_relative "notifier/detected"
|
7
|
-
|
8
|
-
require_relative "ui"
|
9
|
-
|
10
|
-
module Guard
|
11
|
-
# The notifier handles sending messages to different notifiers. Currently the
|
12
|
-
# following
|
13
|
-
# libraries are supported:
|
14
|
-
#
|
15
|
-
# * Ruby GNTP
|
16
|
-
# * Growl
|
17
|
-
# * Libnotify
|
18
|
-
# * rb-notifu
|
19
|
-
# * emacs
|
20
|
-
# * Terminal Notifier
|
21
|
-
# * Terminal Title
|
22
|
-
# * Tmux
|
23
|
-
#
|
24
|
-
# Please see the documentation of each notifier for more information about
|
25
|
-
# the requirements
|
26
|
-
# and configuration possibilities.
|
27
|
-
#
|
28
|
-
# Guard knows four different notification types:
|
29
|
-
#
|
30
|
-
# * success
|
31
|
-
# * pending
|
32
|
-
# * failed
|
33
|
-
# * notify
|
34
|
-
#
|
35
|
-
# The notification type selection is based on the image option that is
|
36
|
-
# sent to {#notify}. Each image type has its own notification type, and
|
37
|
-
# notifications with custom images goes all sent as type `notify`. The
|
38
|
-
# `gntp` notifier is able to register these types
|
39
|
-
# at Growl and allows customization of each notification type.
|
40
|
-
#
|
41
|
-
# Guard can be configured to make use of more than one notifier at once.
|
42
|
-
#
|
43
|
-
# @see Guard::Dsl
|
44
|
-
#
|
45
|
-
# TODO: rename to plural
|
46
|
-
module Notifier
|
47
|
-
extend self
|
48
|
-
|
49
|
-
NOTIFICATIONS_DISABLED = "Notifications disabled by GUARD_NOTIFY" +
|
50
|
-
" environment variable"
|
51
|
-
|
52
|
-
USING_NOTIFIER = "Guard is using %s to send notifications."
|
53
|
-
|
54
|
-
ONLY_NOTIFY = "Only notify() is available from a child process"
|
55
|
-
|
56
|
-
DEPRECTED_IMPLICIT_CONNECT = "Calling Guard::Notifier.notify()" +
|
57
|
-
" without a prior Notifier.connect() is deprecated"
|
58
|
-
|
59
|
-
# List of available notifiers, grouped by functionality
|
60
|
-
SUPPORTED = [
|
61
|
-
{
|
62
|
-
gntp: GNTP,
|
63
|
-
growl: Growl,
|
64
|
-
terminal_notifier: TerminalNotifier,
|
65
|
-
libnotify: Libnotify,
|
66
|
-
notifysend: NotifySend,
|
67
|
-
notifu: Notifu
|
68
|
-
},
|
69
|
-
{ emacs: Emacs },
|
70
|
-
{ tmux: Tmux },
|
71
|
-
{ terminal_title: TerminalTitle },
|
72
|
-
{ file: FileNotifier }
|
73
|
-
]
|
74
|
-
|
75
|
-
class NotServer < RuntimeError
|
76
|
-
end
|
77
|
-
|
78
|
-
def connect(options = {})
|
79
|
-
@detected = Detected.new(SUPPORTED)
|
80
|
-
return if _client?
|
81
|
-
|
82
|
-
_env.notify_pid = $$
|
83
|
-
|
84
|
-
fail "Already connected" if active?
|
85
|
-
|
86
|
-
return unless enabled? && options[:notify]
|
87
|
-
|
88
|
-
turn_on
|
89
|
-
rescue Detected::NoneAvailableError => e
|
90
|
-
::Guard::UI.info e.to_s
|
91
|
-
end
|
92
|
-
|
93
|
-
def disconnect
|
94
|
-
if _client?
|
95
|
-
@detected = nil
|
96
|
-
return
|
97
|
-
end
|
98
|
-
|
99
|
-
turn_off if active?
|
100
|
-
@detected.reset
|
101
|
-
_env.notify_pid = nil
|
102
|
-
@detected = nil
|
103
|
-
end
|
104
|
-
|
105
|
-
# Turn notifications on.
|
106
|
-
#
|
107
|
-
# @param [Hash] options the turn_on options
|
108
|
-
# @option options [Boolean] silent disable any logging
|
109
|
-
#
|
110
|
-
def turn_on(opts = {})
|
111
|
-
_check_server!
|
112
|
-
return unless enabled?
|
113
|
-
|
114
|
-
fail "Already active!" if active?
|
115
|
-
|
116
|
-
silent = opts[:silent]
|
117
|
-
|
118
|
-
@detected.available.each do |klass, _|
|
119
|
-
::Guard::UI.info(format(USING_NOTIFIER, klass.title)) unless silent
|
120
|
-
klass.turn_on if klass.respond_to?(:turn_on)
|
121
|
-
end
|
122
|
-
|
123
|
-
_env.notify_active = true
|
124
|
-
end
|
125
|
-
|
126
|
-
# Turn notifications off.
|
127
|
-
def turn_off
|
128
|
-
_check_server!
|
129
|
-
|
130
|
-
fail "Not active!" unless active?
|
131
|
-
|
132
|
-
@detected.available.each do |klass, _|
|
133
|
-
klass.turn_off if klass.respond_to?(:turn_off)
|
134
|
-
end
|
135
|
-
|
136
|
-
_env.notify_active = false
|
137
|
-
end
|
138
|
-
|
139
|
-
# Toggle the system notifications on/off
|
140
|
-
def toggle
|
141
|
-
unless enabled?
|
142
|
-
::Guard::UI.error NOTIFICATIONS_DISABLED
|
143
|
-
return
|
144
|
-
end
|
145
|
-
|
146
|
-
if active?
|
147
|
-
::Guard::UI.info "Turn off notifications"
|
148
|
-
turn_off
|
149
|
-
return
|
150
|
-
end
|
151
|
-
|
152
|
-
turn_on
|
153
|
-
end
|
154
|
-
|
155
|
-
# Test if the notifications can be enabled based on ENV['GUARD_NOTIFY']
|
156
|
-
def enabled?
|
157
|
-
_env.notify?
|
158
|
-
end
|
159
|
-
|
160
|
-
# Test if notifiers are currently turned on
|
161
|
-
def active?
|
162
|
-
_env.notify_active?
|
163
|
-
end
|
164
|
-
|
165
|
-
# Add a notification library to be used.
|
166
|
-
#
|
167
|
-
# @param [Symbol] name the name of the notifier to use
|
168
|
-
# @param [Hash] options the notifier options
|
169
|
-
# @option options [String] silent disable any error message
|
170
|
-
# @return [Boolean] if the notification could be added
|
171
|
-
#
|
172
|
-
def add(name, opts = {})
|
173
|
-
_check_server!
|
174
|
-
|
175
|
-
return false unless enabled?
|
176
|
-
|
177
|
-
if name == :off && active?
|
178
|
-
turn_off
|
179
|
-
return false
|
180
|
-
end
|
181
|
-
|
182
|
-
# ok to pass new instance when called without connect (e.g. evaluator)
|
183
|
-
(@detected || Detected.new(SUPPORTED)).add(name, opts)
|
184
|
-
end
|
185
|
-
|
186
|
-
# TODO: deprecate/remove
|
187
|
-
alias :add_notifier :add
|
188
|
-
|
189
|
-
# Show a system notification with all configured notifiers.
|
190
|
-
#
|
191
|
-
# @param [String] message the message to show
|
192
|
-
# @option opts [Symbol, String] image the image symbol or path to an image
|
193
|
-
# @option opts [String] title the notification title
|
194
|
-
#
|
195
|
-
def notify(message, message_opts = {})
|
196
|
-
if _client?
|
197
|
-
# TODO: remove
|
198
|
-
UI.deprecation(DEPRECTED_IMPLICIT_CONNECT)
|
199
|
-
return unless enabled?
|
200
|
-
connect(notify: true)
|
201
|
-
else
|
202
|
-
return unless active?
|
203
|
-
end
|
204
|
-
|
205
|
-
@detected.available.each do |klass, options|
|
206
|
-
_notify(klass, options, message, message_opts)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
# Used by dsl describer
|
211
|
-
def notifiers
|
212
|
-
@detected.available.map { |mod, opts| { name: mod.name, options: opts } }
|
213
|
-
end
|
214
|
-
|
215
|
-
private
|
216
|
-
|
217
|
-
def _env
|
218
|
-
(@environment ||= _create_env)
|
219
|
-
end
|
220
|
-
|
221
|
-
def _create_env
|
222
|
-
Internals::Environment.new("GUARD").tap do |env|
|
223
|
-
env.create_method(:notify?) { |data| data != "false" }
|
224
|
-
env.create_method(:notify_pid) { |data| data && Integer(data) }
|
225
|
-
env.create_method(:notify_pid=)
|
226
|
-
env.create_method(:notify_active?)
|
227
|
-
env.create_method(:notify_active=)
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
def _check_server!
|
232
|
-
_client? && fail(NotServer, ONLY_NOTIFY)
|
233
|
-
end
|
234
|
-
|
235
|
-
def _client?
|
236
|
-
(pid = _env.notify_pid) && (pid != $$)
|
237
|
-
end
|
238
|
-
|
239
|
-
def _notify(klass, options, message, message_options)
|
240
|
-
notifier = klass.new(options)
|
241
|
-
notifier.notify(message, message_options.dup)
|
242
|
-
rescue RuntimeError => e
|
243
|
-
::Guard::UI.error "Notification failed for #{notifier.name}: #{e.message}"
|
244
|
-
::Guard::UI.debug e.backtrace.join("\n")
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|