Class: Gitdocs::Notifier
- Inherits:
-
Object
- Object
- Gitdocs::Notifier
- Defined in:
- lib/gitdocs/notifier.rb
Overview
Wrapper for the UI notifier
Constant Summary collapse
- INFO_ICON =
File.('../../img/icon.png', __FILE__)
Class Method Summary collapse
-
.error(title, message) ⇒ Object
Wrapper around #error for a single call to the notifier.
Instance Method Summary collapse
- #error(title, message) ⇒ Object
- #info(title, message) ⇒ Object
-
#initialize(show_notifications) ⇒ Notifier
constructor
A new instance of Notifier.
- #merge_notification(result, root) ⇒ Object
- #push_notification(result, root) ⇒ Object
- #warn(title, message) ⇒ Object
Constructor Details
#initialize(show_notifications) ⇒ Notifier
Returns a new instance of Notifier.
14 15 16 17 |
# File 'lib/gitdocs/notifier.rb', line 14 def initialize(show_notifications) @show_notifications = show_notifications Guard::Notifier.turn_on if @show_notifications end |
Class Method Details
Instance Method Details
#error(title, message) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/gitdocs/notifier.rb', line 45 def error(title, ) if @show_notifications Guard::Notifier.notify(, title: title, image: :failure) else Kernel.warn("#{title}: #{}") end rescue # rubocop:disable Lint/HandleExceptions # Prevent StandardErrors from stopping the daemon. end |
#info(title, message) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/gitdocs/notifier.rb', line 21 def info(title, ) if @show_notifications Guard::Notifier.notify(, title: title, image: INFO_ICON) else puts("#{title}: #{}") end rescue # rubocop:disable Lint/HandleExceptions # Prevent StandardErrors from stopping the daemon. end |
#merge_notification(result, root) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gitdocs/notifier.rb', line 57 def merge_notification(result, root) return if result.nil? return if result == :no_remote return if result == :ok return if result == {} if result.is_a?(Array) warn( 'There were some conflicts', result.map { |f| "* #{f}" }.join("\n") ) elsif result.is_a?(Hash) info( "Updated with #{change_to_s(result)}", "In #{root}:\n#{(result)}" ) else error( 'There was a problem synchronizing this gitdoc', "A problem occurred in #{root}:\n#{result}" ) end end |
#push_notification(result, root) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/gitdocs/notifier.rb', line 83 def push_notification(result, root) return if result.nil? return if result == :no_remote return if result == :nothing if result == :conflict warn("There was a conflict in #{root}, retrying", '') elsif result.is_a?(Hash) info("Pushed #{change_to_s(result)}", "#{root} has been pushed") else error("BAD Could not push changes in #{root}", result.to_s) end end |
#warn(title, message) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/gitdocs/notifier.rb', line 33 def warn(title, ) if @show_notifications Guard::Notifier.notify(, title: title) else Kernel.warn("#{title}: #{}") end rescue # rubocop:disable Lint/HandleExceptions # Prevent StandardErrors from stopping the daemon. end |