class Notiffany::Notifier
Constants
- Env
- NOTIFICATIONS_DISABLED
- ONLY_NOTIFY
- SUPPORTED
-
List of available notifiers, grouped by functionality
- USING_NOTIFIER
- YamlEnvStorage
-
TODO: use a socket instead of passing env variables to child processes (currently probably only used by guard-cucumber anyway)
Attributes
Public Class Methods
Source
# File lib/notiffany/notifier.rb, line 82 def initialize(opts) @config = Config.new(opts) @detected = Detected.new(SUPPORTED, config.env_namespace, config.logger) return if _client? _activate rescue Detected::NoneAvailableError => e config.logger.info e.to_s end
Public Instance Methods
Source
# File lib/notiffany/notifier.rb, line 138 def active? _env.notify_active? end
Test if notifiers are currently turned on
Source
# File lib/notiffany/notifier.rb, line 160 def available @detected.available end
Source
# File lib/notiffany/notifier.rb, line 92 def disconnect if _client? @detected = nil return end turn_off if active? @detected.reset unless @detected.nil? _env.notify_pid = nil @detected = nil end
Source
# File lib/notiffany/notifier.rb, line 133 def enabled? _env.notify? end
Test if the notifications can be enabled based on ENV
Source
# File lib/notiffany/notifier.rb, line 148 def notify(message, message_opts = {}) if _client? return unless enabled? else return unless active? end @detected.available.each do |notifier| notifier.notify(message, message_opts.dup) end end
Show a system notification with all configured notifiers.
@param [String] message the message to show @option opts [Symbol, String] image the image symbol or path to an image @option opts [String] title the notification title
Source
# File lib/notiffany/notifier.rb, line 120 def turn_off _check_server! fail "Not active!" unless active? @detected.available.each do |obj| obj.turn_off if obj.respond_to?(:turn_off) end _env.notify_active = false end
Turn notifications off.
Source
# File lib/notiffany/notifier.rb, line 109 def turn_on(options = {}) _check_server! return unless enabled? fail "Already active!" if active? _turn_on_notifiers(options) _env.notify_active = true end
Turn notifications on.
@param [Hash] options the turn_on
options @option options [Boolean] silent disable any logging
Private Instance Methods
Source
# File lib/notiffany/notifier.rb, line 191 def _activate _env.notify_pid = $$ fail "Already connected" if active? return unless _notification_wanted? _detect_or_add_notifiers turn_on end
Source
# File lib/notiffany/notifier.rb, line 170 def _check_server! _client? && fail(NotServer, ONLY_NOTIFY) end
Source
# File lib/notiffany/notifier.rb, line 174 def _client? (pid = _env.notify_pid) && (pid != $$) end
Source
# File lib/notiffany/notifier.rb, line 178 def _detect_or_add_notifiers notifiers = config.notifiers return @detected.detect if notifiers.empty? notifiers.each do |name, notifier_options| @detected.add(name, notifier_options) end end
Source
# File lib/notiffany/notifier.rb, line 166 def _env @environment ||= Env.new(config.env_namespace) end
Source
# File lib/notiffany/notifier.rb, line 187 def _notification_wanted? enabled? && config.notify? end
Source
# File lib/notiffany/notifier.rb, line 202 def _turn_on_notifiers(options) silent = options[:silent] @detected.available.each do |obj| config.logger.debug(format(USING_NOTIFIER, obj.title)) unless silent obj.turn_on if obj.respond_to?(:turn_on) end end