Class: Guard::Notifier::GrowlNotify

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

Overview

System notifications using the [GrowlNotify](github.com/scottdavis/growl_notify) gem.

This gem is available for OS X and sends system notifications to [Growl](growl.info) through AppleScript.

Examples:

Add the `growl_notify` gem to your `Gemfile`

group :development
  gem 'growl_notify'
end

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

notification :growl_notify

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

notification :growl_notify, sticky: true

Constant Summary

DEFAULTS =

Default options for the growl_notify 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

+ (Boolean) _register!(options)

Detects if the GrowlNotify gem is available and if not, displays an error message unless `opts` is true. If it's available, GrowlNotify is configured for Guard.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/guard/notifiers/growl_notify.rb', line 46

def self._register!(options)
  if ::GrowlNotify.application_name != 'Guard'
    ::GrowlNotify.config do |c|
      c.notifications         = %w(success pending failed notify)
      c.default_notifications = 'notify'
      c.application_name      = 'Guard'
    end
  end

  true

rescue ::GrowlNotify::GrowlNotFound
  unless options[:silent]
    ::Guard::UI.error 'Please install Growl from http://growl.info'
  end
  false
end

+ (Boolean) available?(opts = {})



34
35
36
# File 'lib/guard/notifiers/growl_notify.rb', line 34

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

+ (Object) supported_hosts



30
31
32
# File 'lib/guard/notifiers/growl_notify.rb', line 30

def self.supported_hosts
  %w[darwin]
end

Instance Method Details

- (Object) notify(message, opts = {})

Shows a system notification.

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)

    if the message should stick to the screen

  • priority (Integer)

    the importance of message from -2 (very low) to 2 (emergency)



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/guard/notifiers/growl_notify.rb', line 76

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

  opts = DEFAULTS.merge(
    application_name: 'Guard',
    with_name:        opts.delete(:type).to_s,
    description:      message,
    icon:             opts.delete(:image)
  ).merge(opts)

  ::GrowlNotify.send_notification(opts)
end