Class: Guard::Notifier
- Inherits:
-
Object
- Object
- Guard::Notifier
- Defined in:
- lib/guard/notifier.rb
Constant Summary collapse
- DEPRECATED_IMPLICIT_CONNECT =
"Calling Notiffany::Notifier.notify()"\ " without a prior Notifier.connect() is"\ " deprecated"
Class Method Summary collapse
- .connect(options = {}) ⇒ Object
-
.detected ⇒ Object
Used by dsl describer.
- .disconnect ⇒ Object
- .notify(message, options = {}) ⇒ Object
-
.supported ⇒ Object
Used by dsl describer.
- .toggle ⇒ Object
- .turn_on ⇒ Object
Class Method Details
.connect(options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/guard/notifier.rb', line 6 def self.connect( = {}) @notifier ||= nil fail "Already connected!" if @notifier begin opts = .merge(namespace: "guard", logger: UI) @notifier = Notiffany.connect(opts) rescue Notiffany::Notifier::Detected::UnknownNotifier => e UI.error "Failed to setup notification: #{e.}" fail end end |
.detected ⇒ Object
Used by dsl describer
65 66 67 68 69 |
# File 'lib/guard/notifier.rb', line 65 def self.detected @notifier.available.map do |mod| { name: mod.name.to_sym, options: mod. } end end |
.disconnect ⇒ Object
18 19 20 21 |
# File 'lib/guard/notifier.rb', line 18 def self.disconnect @notifier && @notifier.disconnect @notifier = nil end |
.notify(message, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/guard/notifier.rb', line 27 def self.notify(, = {}) unless @notifier # TODO: reenable again? # UI.deprecation(DEPRECTED_IMPLICIT_CONNECT) connect(notify: true) end @notifier.notify(, ) rescue RuntimeError => e UI.error "Notification failed for #{@notifier.class.name}: #{e.}" UI.debug e.backtrace.join("\n") end |
.supported ⇒ Object
Used by dsl describer
60 61 62 |
# File 'lib/guard/notifier.rb', line 60 def self.supported Notiffany::Notifier::SUPPORTED.inject(:merge) end |
.toggle ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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 ⇒ Object
40 41 42 |
# File 'lib/guard/notifier.rb', line 40 def self.turn_on @notifier.turn_on end |