class Notiffany::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.

Private Instance Methods

_check_available(_opts = {}) click to toggle source
# File lib/notiffany/notifier/notifysend.rb, line 34
def _check_available(_opts = {})
  which = Shellany::Sheller.stdout("which notify-send")

  return true unless which.nil? || which.empty?

  fail UnavailableError, "libnotify-bin package is not installed"
end
_gem_name() click to toggle source

notify-send has no gem, just a binary to shell out

# File lib/notiffany/notifier/notifysend.rb, line 26
def _gem_name
  nil
end
_notifysend_urgency(type) click to toggle source

Converts Guards notification type to the best matching notify-send urgency.

@param [String] type the Guard notification type @return [String] the notify-send urgency

# File lib/notiffany/notifier/notifysend.rb, line 71
def _notifysend_urgency(type)
  { failed: "normal", pending: "low" }.fetch(type, "low")
end
_perform_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/notiffany/notifier/notifysend.rb, line 54
def _perform_notify(message, opts = {})
  command = [opts[:title], message]
  opts = opts.merge(
    i: opts[:i] || opts[:image],
    u: opts[:u] || _notifysend_urgency(opts[:type])
  )

  Shellany::Sheller.
    run("notify-send", *_to_arguments(command, SUPPORTED, opts))
end
_supported_hosts() click to toggle source
# File lib/notiffany/notifier/notifysend.rb, line 30
def _supported_hosts
  %w(linux linux-gnu freebsd openbsd sunos solaris)
end
_to_arguments(command, supported, opts = {}) click to toggle source

Builds a shell command out of a command string and option hash.

@param [String] command the command execute @param [Array] supported list of supported option flags @param [Hash] opts additional command options

@return [Array<String>] the command and its options converted to a shell command.

# File lib/notiffany/notifier/notifysend.rb, line 84
def _to_arguments(command, supported, opts = {})
  opts.inject(command) do |cmd, (flag, value)|
    supported.include?(flag) ? (cmd << "-#{flag}" << value.to_s) : cmd
  end
end