Module: Guard::Notifier

Defined in:
lib/guard/notifier.rb

Overview

The notifier class handles cross-platform system notifications that supports:

  • Growl on Mac OS X

  • Libnotify on Linux

  • Notifu on Windows

Constant Summary collapse

APPLICATION_NAME =

Application name as shown in the specific notification settings

"Guard"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.gntpObject

Returns the value of attribute gntp.



20
21
22
# File 'lib/guard/notifier.rb', line 20

def gntp
  @gntp
end

.growl_libraryObject

Returns the value of attribute growl_library.



20
21
22
# File 'lib/guard/notifier.rb', line 20

def growl_library
  @growl_library
end

Class Method Details

.enabled?Boolean

Test if the notifications are enabled and available.

Returns:

  • (Boolean)

    whether the notifications are available



73
74
75
# File 'lib/guard/notifier.rb', line 73

def enabled?
  ENV["GUARD_NOTIFY"] == 'true'
end

.notify(message, options = { }) ⇒ Object

Show a message with the system notification.

Parameters:

  • the (String)

    message to show

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

    a customizable set of options

Options Hash (options):

  • image (Symbol, String)

    the image symbol or path to an image

  • title (String)

    the notification title

See Also:

  • image_path


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

def notify(message, options = { })
  if enabled?
    image = options.delete(:image) || :success
    title = options.delete(:title) || "Guard"

    case RbConfig::CONFIG['target_os']
    when /darwin/i
      notify_mac(title, message, image, options)
    when /linux/i
      notify_linux(title, message, image, options)
    when /mswin|mingw/i
      notify_windows(title, message, image, options)
    end
  end
end

.turn_offObject

Turn notifications off.



24
25
26
# File 'lib/guard/notifier.rb', line 24

def turn_off
  ENV["GUARD_NOTIFY"] = 'false'
end

.turn_onBoolean

Turn notifications on. This tries to load the platform specific notification library.

Returns:

  • (Boolean)

    whether the notification could be enabled.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/guard/notifier.rb', line 33

def turn_on
  ENV["GUARD_NOTIFY"] = 'true'
  case RbConfig::CONFIG['target_os']
  when /darwin/i
    require_growl
  when /linux/i
    require_libnotify
  when /mswin|mingw/i
    require_rbnotifu
  end
end