Class: Notiffany::Notifier::Detected
- Inherits:
-
Object
- Object
- Notiffany::Notifier::Detected
- Defined in:
- lib/notiffany/notifier/detected.rb
Defined Under Namespace
Classes: NoneAvailableError, UnknownNotifier
Constant Summary collapse
- NO_SUPPORTED_NOTIFIERS =
"Notiffany could not detect any of the"\ " supported notification libraries."
Instance Method Summary collapse
-
#add(name, opts) ⇒ Object
Called when user has notifier-specific config.
- #available ⇒ Object
- #detect ⇒ Object
-
#initialize(supported, env_namespace, logger) ⇒ Detected
constructor
A new instance of Detected.
- #reset ⇒ Object
Constructor Details
#initialize(supported, env_namespace, logger) ⇒ Detected
Returns a new instance of Detected.
47 48 49 50 51 |
# File 'lib/notiffany/notifier/detected.rb', line 47 def initialize(supported, env_namespace, logger) @supported = supported @environment = YamlEnvStorage.new(env_namespace) @logger = logger end |
Instance Method Details
#add(name, opts) ⇒ Object
Called when user has notifier-specific config. Honor the config by warning if something is wrong
82 83 84 85 86 |
# File 'lib/notiffany/notifier/detected.rb', line 82 def add(name, opts) _add(name, opts) rescue Notifier::Base::UnavailableError => e @logger.warning("Notiffany: #{name} not available (#{e.}).") end |
#available ⇒ Object
74 75 76 77 78 |
# File 'lib/notiffany/notifier/detected.rb', line 74 def available @available ||= _notifiers.map do |entry| _to_module(entry[:name]).new(entry[:options]) end end |
#detect ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/notiffany/notifier/detected.rb', line 57 def detect return unless _notifiers.empty? @supported.each do |group| group.detect do |name, _| begin _add(name, {}) true rescue Notifier::Base::UnavailableError => e @logger.debug "Notiffany: #{name} not available (#{e.})." false end end end fail NoneAvailableError, NO_SUPPORTED_NOTIFIERS if _notifiers.empty? end |
#reset ⇒ Object
53 54 55 |
# File 'lib/notiffany/notifier/detected.rb', line 53 def reset @environment.notifiers = [] end |