Class: Guard::Notifier::Libnotify

Inherits:
Base
  • Object
show all
Defined in:
lib/guard/notifiers/libnotify.rb

Overview

System notifications using the [libnotify](github.com/splattael/libnotify) gem.

This gem is available for Linux, FreeBSD, OpenBSD and Solaris and sends system notifications to Gnome [libnotify](developer.gnome.org/libnotify):

Examples:

Add the `libnotify` gem to your `Gemfile`

group :development
  gem 'libnotify'
end

Add the `:libnotify` notifier to your `Guardfile`

notification :libnotify

Add the `:libnotify` notifier with configuration options to your `Guardfile`

notification :libnotify, timeout: 5, transient: true, append: false, urgency: :critical

Constant Summary

DEFAULTS =

Default options for the libnotify notifications.

{
  transient: false,
  append:    true,
  timeout:   3
}

Constants inherited from Base

Base::HOSTS

Instance Attribute Summary

Attributes inherited from Base

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

_supported_host?, gem_name, #images_path, #initialize, name, #name, #normalize_standard_options!, require_gem_safely, title, #title

Constructor Details

This class inherits a constructor from Guard::Notifier::Base

Class Method Details

.available?(opts = {}) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/guard/notifiers/libnotify.rb', line 37

def self.available?(opts = {})
  super and require_gem_safely(opts)
end

.supported_hostsObject



33
34
35
# File 'lib/guard/notifiers/libnotify.rb', line 33

def self.supported_hosts
  %w[linux freebsd openbsd sunos solaris]
end

Instance Method Details

#notify(message, opts = {}) ⇒ Object

Shows a system notification.

Parameters:

  • message (String)

    the notification message body

  • opts (Hash) (defaults to: {})

    additional notification library options

Options Hash (opts):

  • type (String)

    the notification type. Either 'success', 'pending', 'failed' or 'notify'

  • title (String)

    the notification title

  • image (String)

    the path to the notification image

  • transient (Boolean)

    keep the notifications around after display

  • append (Boolean)

    append onto existing notification

  • timeout (Number, Boolean)

    the number of seconds to display (1.5 (s), 1000 (ms), false)



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/guard/notifiers/libnotify.rb', line 55

def notify(message, opts = {})
  super
  self.class.require_gem_safely

  opts = DEFAULTS.merge(
    summary:   opts.delete(:title),
    icon_path: opts.delete(:image),
    body:      message,
    urgency:   _libnotify_urgency(opts.delete(:type))
  ).merge(opts)

  ::Libnotify.show(opts)
end