Files

Guard::Notifier::NotifySend

System notifications using notify-send, a binary that ships with the libnotify-bin package on many Debian-based distributions.

@example Add the `:notifysend` notifier to your `Guardfile`

notification :notifysend

Constants

DEFAULTS

Default options for the notify-send notifications.

SUPPORTED

Full list of options supported by notify-send.

Public Class Methods

_notifysend_binary_available?() click to toggle source

@private

@return [Boolean] whether or not the notify-send binary is available

# File lib/guard/notifiers/notifysend.rb, line 35
def self._notifysend_binary_available?
  !`which notify-send`.empty?
end
_register!(opts) click to toggle source

@private

Detects if the notify-send binary is available and if not, displays an error message unless `opts` is true.

@return [Boolean] whether or not the notify-send binary is available

# File lib/guard/notifiers/notifysend.rb, line 46
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
available?(opts = {}) click to toggle source
# File lib/guard/notifiers/notifysend.rb, line 27
def self.available?(opts = {})
  super and _register!(opts)
end
supported_hosts() click to toggle source
# File lib/guard/notifiers/notifysend.rb, line 23
def self.supported_hosts
  ]linux freebsd openbsd sunos solaris]
end

Public Instance Methods

notify(message, opts = {}) click to toggle source

Shows a system notification.

@param [String] message the notification message body @param [Hash] opts additional notification library options @option opts [String] type the notification type. Either ‘success’,

'pending', 'failed' or 'notify'

@option opts [String] title the notification title @option opts [String] image the path to the notification image @option opts [String] c the notification category @option opts [Number] t the number of milliseconds to display (1000,

3000)
# File lib/guard/notifiers/notifysend.rb, line 69
def notify(message, opts = {})
  super

  command = [opts[: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

[Validate]

Generated with the Darkfish Rdoc Generator 2.