Files

Guard::Notifier::GNTP

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):

@example Add the `ruby_gntp` gem to your `Gemfile`

group :development
  gem 'ruby_gntp'
end

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

notification :gntp

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

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

Constants

DEFAULTS

Default options for the ruby gtnp gem

Public Instance Methods

available?(silent = false, options = {}) click to toggle source

Test if the notification library is available.

@param [Boolean] silent true if no error messages should be shown @param [Hash] options notifier options @return [Boolean] the availability status

# File lib/guard/notifiers/gntp.rb, line 60
def available?(silent = false, options = {})
  if RbConfig::CONFIG['host_os'] =~ /darwin|linux|freebsd|openbsd|sunos|solaris|mswin|mingw|cygwin/
    require 'ruby_gntp'
    true

  else
    ::Guard::UI.error 'The :gntp notifier runs only on Mac OS X, Linux, FreeBSD, OpenBSD, Solaris and Windows.' unless silent
    false
  end

rescue LoadError
  ::Guard::UI.error "Please add \"gem 'ruby_gntp'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
  false
end
notify(type, title, message, image, options = { }) click to toggle source

Show a system notification.

@param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify' @param [String] title the notification title @param [String] message the notification message body @param [String] image the path to the notification image @param [Hash] options additional notification library options @option options [String] host the hostname or IP address to which to send a remote notification @option options [String] password the password used for remote notifications @option options [Integer] port the port to send a remote notification @option options [Boolean] sticky make the notification sticky

# File lib/guard/notifiers/gntp.rb, line 87
def notify(type, title, message, image, options = { })
  require 'ruby_gntp'

  options = DEFAULTS.merge(options)

  gntp = ::GNTP.new('Guard', options.delete(:host), options.delete(:password), options.delete(:port))

  unless registered?
    gntp.register({
        :app_icon => File.expand_path(File.join(__FILE__, '..', '..', '..', '..', 'images', 'guard.png')),
        :notifications => [
            { :name => 'notify', :enabled => true },
            { :name => 'failed', :enabled => true },
            { :name => 'pending', :enabled => true },
            { :name => 'success', :enabled => true }
        ]
    })

    registered!
  end

  gntp.notify(options.merge({
      :name  => type,
      :title => title,
      :text  => message,
      :icon  => image
  }))
end
registered!() click to toggle source

Mark the notifier as registered.

# File lib/guard/notifiers/gntp.rb, line 50
def registered!
  @registered = true
end
registered?() click to toggle source

Is this notifier already registered

@return [Boolean] registration status

# File lib/guard/notifiers/gntp.rb, line 44
def registered?
  @registered ||= false
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.