Module: NRSER::Notify

Extended by:
MethodDecorators
Defined in:
lib/nrser/notify.rb,
lib/nrser/notify/version.rb

Overview

Definitions

Constant Summary collapse

ROOT =

Absolute, expanded path to the gem’s root directory.

Here in ‘//lib/nrser/version` so that it can be used via

require 'nrser/version'

without loading the entire module.

Returns:

  • (Pathname)
(
  Pathname.new( __FILE__ ).dirname / '..' / '..' / '..'
).expand_path
VERSION =

String version of the gem.

Returns:

  • (String)
(ROOT / 'VERSION').read

Class Method Summary collapse

Class Method Details

.available?Boolean

Can we send notification to the user?

Right now, only terminal_notifier? is tested, but we can add more options in the future.

Returns:

  • (Boolean)


70
71
72
# File 'lib/nrser/notify.rb', line 70

def self.available?
  terminal_notifier?
end

.notify(message, **options, &block) ⇒ Object

Send a notification to the use if notifications are available?.



77
78
79
80
# File 'lib/nrser/notify.rb', line 77

def self.notify message, **options, &block
  return false unless available?
  notify! message, **options, &block
end

.notify!(message, **options, &block) ⇒ Object

Force sending of a notification regardless of available?.



85
86
87
88
# File 'lib/nrser/notify.rb', line 85

def self.notify! message, **options, &block
  require 'terminal-notifier'
  TerminalNotifier.notify message, **options, &block
end

.terminal_notifier?Boolean

Is the ‘terminal-notifier` gem available?

terminal-notifier][

is not an NRSER dependency since it does not make

sense for many systems and situations. It must be installed separately.

[terminal-notifier]: rubygems.org/gems/terminal-notifier

Tests by trying to ‘require` it.

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
# File 'lib/nrser/notify.rb', line 51

def self.terminal_notifier?
  begin
    require 'terminal-notifier'
  rescue LoadError => error
    false
  else
    TerminalNotifier.available?
  end
end