class Guard::Notifier::NotifySend
notification :notifysend
@example Add the ‘:notifysend` notifier to your `Guardfile`
the libnotify-bin package on many Debian-based distributions.
System notifications using notify-send, a binary that ships with
def self._notifysend_binary_available?
-
(Boolean)- whether or not the notify-send binary is available
Other tags:
- Private: -
def self._notifysend_binary_available? !`which notify-send`.empty? end
def self._register!(opts)
-
(Boolean)- whether or not the notify-send binary is available
Other tags:
- Private: -
def self._register!(opts) if _notifysend_binary_available? true else unless opts[:silent] ::Guard::UI.error 'The :notifysend notifier runs only on Linux, FreeBSD, OpenBSD and Solaris with the libnotify-bin package installed.' end false end end
def self.available?(opts = {})
def self.available?(opts = {}) super and _register!(opts) end
def self.supported_hosts
def self.supported_hosts %w[linux freebsd openbsd sunos solaris] end
def _notifysend_urgency(type)
-
(String)- the notify-send urgency
Parameters:
-
type(String) -- the Guard notification type
def _notifysend_urgency(type) { 'failed' => 'normal', 'pending' => 'low' }.fetch(type, 'low') end
def _to_arguments(command, supported, opts = {})
-
(Array- the command and its options converted to a shell command.)
Parameters:
-
opts(Hash) -- additional command options -
supported(Array) -- list of supported option flags -
command(String) -- the command execute
def _to_arguments(command, supported, opts = {}) opts.reduce(command) do |cmd, (flag, value)| supported.include?(flag) ? (cmd << "-#{ flag }" << value.to_s) : cmd end end
def notify(message, opts = {})
(**opts)-
t(Number) -- the number of milliseconds to display (1000, -
c(String) -- the notification category -
image(String) -- the path to the notification image -
title(String) -- the notification title -
type(String) -- the notification type. Either 'success',
Parameters:
-
opts(Hash) -- additional notification library options -
message(String) -- the notification message body
def notify(message, opts = {}) super command = [title, message] opts = DEFAULTS.merge( i: opts.delete(:image), u: _notifysend_urgency(opts.delete(:type)) ).merge(opts) system('notify-send', *_to_arguments(command, SUPPORTED, opts)) end