Module: Notifier

Extended by:
Notifier
Included in:
Notifier
Defined in:
lib/notifier.rb,
lib/notifier/snarl.rb,
lib/notifier/kdialog.rb,
lib/notifier/knotify.rb,
lib/notifier/osd_cat.rb,
lib/notifier/placebo.rb,
lib/notifier/version.rb,
lib/notifier/notify_send.rb,
lib/notifier/terminal_notifier.rb

Defined Under Namespace

Modules: Kdialog, Knotify, NotifySend, OsdCat, Placebo, Snarl, TerminalNotifier, Version

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.default_notifierObject

Returns the value of attribute default_notifier.



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

def default_notifier
  @default_notifier
end

Instance Method Details

#from_name(name) ⇒ Object



48
49
50
51
52
# File 'lib/notifier.rb', line 48

def from_name(name)
  const_get(classify(name.to_s))
rescue StandardError
  nil
end

#notifierObject



30
31
32
# File 'lib/notifier.rb', line 30

def notifier
  supported_notifier_from_name(default_notifier) || supported_notifiers.first
end

#notifiersObject



38
39
40
41
42
# File 'lib/notifier.rb', line 38

def notifiers
  constants.filter_map do |name|
    const_get(name) unless skip_constants.include?(name.to_s)
  end + [Placebo]
end

#notify(options) ⇒ Object



34
35
36
# File 'lib/notifier.rb', line 34

def notify(options)
  notifier.notify(options)
end

#os?(regex) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/notifier.rb', line 59

def os?(regex)
  RUBY_PLATFORM =~ regex || RbConfig::CONFIG["host_os"] =~ regex
end

#skip_constantsObject



26
27
28
# File 'lib/notifier.rb', line 26

def skip_constants
  @skip_constants ||= %w[Placebo Adapters Version]
end

#supported_notifier_from_name(name) ⇒ Object



54
55
56
57
# File 'lib/notifier.rb', line 54

def supported_notifier_from_name(name)
  notifier = from_name(name)
  notifier&.supported? ? notifier : nil
end

#supported_notifiersObject



44
45
46
# File 'lib/notifier.rb', line 44

def supported_notifiers
  notifiers.select(&:supported?)
end