Class: Notiffany::Notifier::TerminalNotifier

Inherits:
Base
  • Object
show all
Defined in:
lib/notiffany/notifier/terminal_notifier.rb

Overview

System notifications using the

[terminal-notifier](github.com/Springest/terminal-notifier-guard)

gem.

This gem is available for OS X 10.8 Mountain Lion and sends notifications to the OS X notification center.

Constant Summary collapse

DEFAULTS =
{ app_name: "Notiffany" }
ERROR_ONLY_OSX10 =
"The :terminal_notifier only runs"\
" on Mac OS X 10.8 and later."

Constants inherited from Base

Base::ERROR_ADD_GEM_AND_RUN_BUNDLE, Base::HOSTS

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#_image_path, #initialize, #name, #notify, #title

Constructor Details

This class inherits a constructor from Notiffany::Notifier::Base

Instance Method Details

#_check_available(_opts = {}) ⇒ Object



27
28
29
30
# File 'lib/notiffany/notifier/terminal_notifier.rb', line 27

def _check_available(_opts = {})
  return if ::TerminalNotifier::Guard.available?
  fail UnavailableError, ERROR_ONLY_OSX10
end

#_gem_nameObject



23
24
25
# File 'lib/notiffany/notifier/terminal_notifier.rb', line 23

def _gem_name
  "terminal-notifier-guard"
end

#_perform_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 (ignored)

  • app_name (String)

    name of your app

  • execute (String)

    a command

  • activate (String)

    an app bundle

  • open (String)

    some url or file



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/notiffany/notifier/terminal_notifier.rb', line 45

def _perform_notify(message, opts = {})
  title = [opts[:app_name], opts[:type].downcase.capitalize].join(" ")
  opts = {
    title: title
  }.merge(opts)
  opts[:message] = message
  opts[:title] ||= title
  opts.delete(:image)
  opts.delete(:app_name)

  ::TerminalNotifier::Guard.execute(false, opts)
end

#_supported_hostsObject



19
20
21
# File 'lib/notiffany/notifier/terminal_notifier.rb', line 19

def _supported_hosts
  %w(darwin)
end