Class: Guard::Notifier::Growl

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

Overview

System notifications using the [growl](github.com/visionmedia/growl) gem.

This gem is available for OS X and sends system notifications to [Growl](growl.info) through the [GrowlNotify](growl.info/downloads) executable.

The `growlnotify` executable must be installed manually or by using [Homebrew](mxcl.github.com/homebrew/).

Sending notifications with this notifier will not show the different Guard notifications in the Growl preferences. Use the :gntp or :growl_notify notifiers if you want to customize each notification type in Growl.

Examples:

Install `growlnotify` with Homebrew

brew install growlnotify

Add the `growl` gem to your `Gemfile`

group :development
  gem 'growl'
end

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

notification :growl

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

notification :growl, sticky: true, host: '192.168.1.5', password: 'secret'

Constant Summary

DEFAULTS =

Default options for the growl notifications.

{
  sticky:   false,
  priority: 0
}

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

._register!(opts) ⇒ Boolean

Detects if the Growl gem is available and if not, displays an error message unless `opts` is true.

Returns:

  • (Boolean)

    whether or not Growl is installed



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

def self._register!(opts)
  if ::Growl.installed?
    true
  else
    unless opts[:silent]
      ::Guard::UI.error "Please install the 'growlnotify' executable (available by installing the 'growl' gem)."
    end
    false
  end
end

.available?(opts = {}) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/guard/notifiers/growl.rb', line 45

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

.supported_hostsObject



41
42
43
# File 'lib/guard/notifiers/growl.rb', line 41

def self.supported_hosts
  %w[darwin]
end

Instance Method Details

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

Shows a system notification.

The documented options are for GrowlNotify 1.3, but the older options are also supported. Please see `growlnotify –help`.

Priority can be one of the following named keys: `Very Low`, `Moderate`, `Normal`, `High`, `Emergency`. It can also be an integer between -2 and 2.

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

  • sticky (Boolean)

    make the notification sticky

  • priority (String, Integer)

    specify an int or named key (default is 0)

  • host (String)

    the hostname or IP address to which to send a remote notification

  • password (String)

    the password used for remote notifications



90
91
92
93
94
95
96
97
98
# File 'lib/guard/notifiers/growl.rb', line 90

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

  opts = DEFAULTS.merge(opts).merge(name: 'Guard')

  ::Growl.notify(message, opts)
end