class Guard::Notifier

Constants

DEPRECATED_IMPLICIT_CONNECT

Public Class Methods

connect(options = {}) click to toggle source
# File lib/guard/notifier.rb, line 6
def self.connect(options = {})
  @notifier ||= nil
  fail "Already connected!" if @notifier
  begin
    opts = options.merge(namespace: "guard", logger: UI)
    @notifier = Notiffany.connect(opts)
  rescue Notiffany::Notifier::Detected::UnknownNotifier => e
    UI.error "Failed to setup notification: #{e.message}"
    fail
  end
end
detected() click to toggle source

Used by dsl describer

# File lib/guard/notifier.rb, line 65
def self.detected
  @notifier.available.map do |mod|
    { name: mod.name.to_sym, options: mod.options }
  end
end
disconnect() click to toggle source
# File lib/guard/notifier.rb, line 18
def self.disconnect
  @notifier && @notifier.disconnect
  @notifier = nil
end
notify(message, options = {}) click to toggle source
# File lib/guard/notifier.rb, line 27
def self.notify(message, options = {})
  unless @notifier
    # TODO: reenable again?
    # UI.deprecation(DEPRECTED_IMPLICIT_CONNECT)
    connect(notify: true)
  end

  @notifier.notify(message, options)
rescue RuntimeError => e
  UI.error "Notification failed for #{@notifier.class.name}: #{e.message}"
  UI.debug e.backtrace.join("\n")
end
supported() click to toggle source

Used by dsl describer

# File lib/guard/notifier.rb, line 60
def self.supported
  Notiffany::Notifier::SUPPORTED.inject(:merge)
end
toggle() click to toggle source
# File lib/guard/notifier.rb, line 44
def self.toggle
  unless @notifier.enabled?
    UI.error NOTIFICATIONS_DISABLED
    return
  end

  if @notifier.active?
    UI.info "Turn off notifications"
    @notifier.turn_off
    return
  end

  @notifier.turn_on
end
turn_on() click to toggle source
# File lib/guard/notifier.rb, line 40
def self.turn_on
  @notifier.turn_on
end