Class: Guard::Notifier::GNTP

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

Overview

System notifications using the [ruby_gntp](github.com/snaka/ruby_gntp) gem.

This gem is available for OS X, Linux and Windows and sends system notifications to the following system notification frameworks through the [Growl Network Transport Protocol](www.growlforwindows.com/gfw/help/gntp.aspx):

Examples:

Add the `ruby_gntp` gem to your `Gemfile`

group :development
  gem 'ruby_gntp'
end

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

notification :gntp

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

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

Constant Summary

DEFAULTS =

Default options for the ruby gtnp notifications.

{
  sticky: false
}
CLIENT_DEFAULTS =

Default options for the ruby gtnp client.

{
  host:     '127.0.0.1',
  password: '',
  port:     23053
}

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?, #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)


51
52
53
# File 'lib/guard/notifiers/gntp.rb', line 51

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

.gem_nameObject



47
48
49
# File 'lib/guard/notifiers/gntp.rb', line 47

def self.gem_name
  'ruby_gntp'
end

.supported_hostsObject



43
44
45
# File 'lib/guard/notifiers/gntp.rb', line 43

def self.supported_hosts
  %w[darwin linux freebsd openbsd sunos solaris mswin mingw cygwin]
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

  • host (String)

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

  • password (String)

    the password used for remote notifications

  • port (Integer)

    the port to send a remote notification

  • sticky (Boolean)

    make the notification sticky



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/guard/notifiers/gntp.rb', line 70

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

  opts = DEFAULTS.merge(
    name: opts.delete(:type).to_s,
    text: message,
    icon: opts.delete(:image)
  ).merge(opts)

  _client(opts).notify(opts)
end