uniform_notifier 1.10.0 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +18 -0
  4. data/Gemfile +3 -1
  5. data/README.md +95 -77
  6. data/Rakefile +13 -11
  7. data/lib/uniform_notifier.rb +38 -6
  8. data/lib/uniform_notifier/airbrake.rb +3 -3
  9. data/lib/uniform_notifier/base.rb +17 -14
  10. data/lib/uniform_notifier/bugsnag.rb +4 -7
  11. data/lib/uniform_notifier/customized_logger.rb +6 -4
  12. data/lib/uniform_notifier/errors.rb +3 -1
  13. data/lib/uniform_notifier/growl.rb +20 -21
  14. data/lib/uniform_notifier/honeybadger.rb +5 -4
  15. data/lib/uniform_notifier/javascript_alert.rb +7 -3
  16. data/lib/uniform_notifier/javascript_console.rb +18 -14
  17. data/lib/uniform_notifier/rails_logger.rb +3 -1
  18. data/lib/uniform_notifier/raise.rb +4 -2
  19. data/lib/uniform_notifier/rollbar.rb +8 -1
  20. data/lib/uniform_notifier/sentry.rb +21 -0
  21. data/lib/uniform_notifier/slack.rb +20 -22
  22. data/lib/uniform_notifier/terminal_notifier.rb +24 -0
  23. data/lib/uniform_notifier/version.rb +3 -1
  24. data/lib/uniform_notifier/xmpp.rb +25 -24
  25. data/spec/spec_helper.rb +8 -6
  26. data/spec/uniform_notifier/airbrake_spec.rb +12 -10
  27. data/spec/uniform_notifier/base_spec.rb +12 -14
  28. data/spec/uniform_notifier/bugsnag_spec.rb +33 -19
  29. data/spec/uniform_notifier/customized_logger_spec.rb +9 -7
  30. data/spec/uniform_notifier/growl_spec.rb +41 -23
  31. data/spec/uniform_notifier/honeybadger_spec.rb +12 -10
  32. data/spec/uniform_notifier/javascript_alert_spec.rb +29 -9
  33. data/spec/uniform_notifier/javascript_console_spec.rb +55 -17
  34. data/spec/uniform_notifier/rails_logger_spec.rb +9 -7
  35. data/spec/uniform_notifier/raise_spec.rb +15 -16
  36. data/spec/uniform_notifier/rollbar_spec.rb +15 -6
  37. data/spec/uniform_notifier/sentry_spec.rb +27 -0
  38. data/spec/uniform_notifier/slack_spec.rb +12 -8
  39. data/spec/uniform_notifier/terminal_notifier_spec.rb +27 -0
  40. data/spec/uniform_notifier/xmpp_spec.rb +21 -15
  41. data/uniform_notifier.gemspec +24 -17
  42. metadata +33 -25
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class CustomizedLogger < Base
3
5
  @logger = nil
@@ -6,7 +8,7 @@ class UniformNotifier
6
8
  @logger
7
9
  end
8
10
 
9
- def self._out_of_channel_notify( data )
11
+ def self._out_of_channel_notify(data)
10
12
  message = data.values.compact.join("\n")
11
13
  @logger.warn message
12
14
  end
@@ -14,10 +16,10 @@ class UniformNotifier
14
16
  def self.setup(logdev)
15
17
  require 'logger'
16
18
 
17
- @logger = Logger.new( logdev )
19
+ @logger = Logger.new(logdev)
18
20
 
19
- def @logger.format_message( severity, timestamp, progname, msg )
20
- "#{timestamp.strftime("%Y-%m-%d %H:%M:%S")}[#{severity}] #{msg}"
21
+ def @logger.format_message(severity, timestamp, _progname, msg)
22
+ "#{timestamp.strftime('%Y-%m-%d %H:%M:%S')}[#{severity}] #{msg}"
21
23
  end
22
24
  end
23
25
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
- class Exception < ::Exception; end
4
+ class Exception < RuntimeError; end
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class Growl < Base
3
5
  @growl = nil
@@ -6,19 +8,21 @@ class UniformNotifier
6
8
  @growl
7
9
  end
8
10
 
9
- def self.setup_connection( growl )
11
+ def self.setup_connection(growl)
10
12
  setup_connection_growl(growl)
11
13
  rescue LoadError
12
14
  begin
13
15
  setup_connection_gntp(growl)
14
16
  rescue LoadError
15
17
  @growl = nil
16
- raise NotificationError.new( 'You must install the ruby-growl or the ruby_gntp gem to use Growl notification: `gem install ruby-growl` or `gem install ruby_gntp`' )
18
+ raise NotificationError,
19
+ 'You must install the ruby-growl or the ruby_gntp gem to use Growl notification: `gem install ruby-growl` or `gem install ruby_gntp`'
17
20
  end
18
21
  end
19
22
 
20
- def self.setup_connection_growl( growl )
23
+ def self.setup_connection_growl(growl)
21
24
  return unless growl
25
+
22
26
  require 'ruby-growl'
23
27
  if growl.instance_of?(Hash)
24
28
  @password = growl.include?(:password) ? growl[:password] : nil
@@ -33,8 +37,9 @@ class UniformNotifier
33
37
  notify 'Uniform Notifier Growl has been turned on' if !growl.instance_of?(Hash) || !growl[:quiet]
34
38
  end
35
39
 
36
- def self.setup_connection_gntp( growl )
40
+ def self.setup_connection_gntp(growl)
37
41
  return unless growl
42
+
38
43
  require 'ruby_gntp'
39
44
  if growl.instance_of?(Hash)
40
45
  @password = growl.include?(:password) ? growl[:password] : nil
@@ -42,34 +47,28 @@ class UniformNotifier
42
47
  end
43
48
  @password ||= nil
44
49
  @host ||= 'localhost'
45
- @growl = GNTP.new('uniform_notifier', @host, @password, 23053)
46
- @growl.register({:notifications => [{
47
- :name => 'uniform_notifier',
48
- :enabled => true,
49
- }]})
50
+ @growl = GNTP.new('uniform_notifier', @host, @password, 23_053)
51
+ @growl.register(notifications: [{ name: 'uniform_notifier', enabled: true }])
50
52
 
51
53
  notify 'Uniform Notifier Growl has been turned on (using GNTP)' if !growl.instance_of?(Hash) || !growl[:quiet]
52
54
  end
53
55
 
54
56
  protected
55
57
 
56
- def self._out_of_channel_notify( data )
58
+ def self._out_of_channel_notify(data)
57
59
  message = data.values.compact.join("\n")
58
60
 
59
- notify( message )
61
+ notify(message)
60
62
  end
61
63
 
62
64
  private
63
- def self.notify( message )
64
- if defined?(::Growl) && @growl.is_a?(::Growl)
65
- @growl.notify( 'uniform_notifier', 'Uniform Notifier', message )
66
- elsif defined?(::GNTP) && @growl.is_a?(::GNTP)
67
- @growl.notify({
68
- :name => 'uniform_notifier',
69
- :title => 'Uniform Notifier',
70
- :text => message
71
- })
72
- end
65
+
66
+ def self.notify(message)
67
+ if defined?(::Growl) && @growl.is_a?(::Growl)
68
+ @growl.notify('uniform_notifier', 'Uniform Notifier', message)
69
+ elsif defined?(::GNTP) && @growl.is_a?(::GNTP)
70
+ @growl.notify(name: 'uniform_notifier', title: 'Uniform Notifier', text: message)
73
71
  end
72
+ end
74
73
  end
75
74
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class HoneybadgerNotifier < Base
3
5
  def self.active?
@@ -10,12 +12,11 @@ class UniformNotifier
10
12
  message = data.values.compact.join("\n")
11
13
 
12
14
  opt = {}
13
- if UniformNotifier.honeybadger.is_a?(Hash)
14
- opt = UniformNotifier.honeybadger
15
- end
15
+ opt = UniformNotifier.honeybadger if UniformNotifier.honeybadger.is_a?(Hash)
16
16
 
17
17
  exception = Exception.new(message)
18
- Honeybadger.notify(exception, opt)
18
+ honeybadger_class = opt[:honeybadger_class] || Honeybadger
19
+ honeybadger_class.notify(exception, opt)
19
20
  end
20
21
  end
21
22
  end
@@ -1,15 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class JavascriptAlert < Base
3
5
  def self.active?
4
- UniformNotifier.alert
6
+ !!UniformNotifier.alert
5
7
  end
6
8
 
7
9
  protected
8
10
 
9
- def self._inline_notify( data )
11
+ def self._inline_notify(data)
10
12
  message = data.values.compact.join("\n")
13
+ options = UniformNotifier.alert.is_a?(Hash) ? UniformNotifier.alert : {}
14
+ script_attributes = options[:attributes] || {}
11
15
 
12
- wrap_js_association "alert( #{message.inspect} );"
16
+ wrap_js_association "alert( #{message.inspect} );", script_attributes
13
17
  end
14
18
  end
15
19
  end
@@ -1,27 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class JavascriptConsole < Base
3
5
  def self.active?
4
- UniformNotifier.console
6
+ !!UniformNotifier.console
5
7
  end
6
8
 
7
9
  protected
8
10
 
9
- def self._inline_notify( data )
11
+ def self._inline_notify(data)
10
12
  message = data.values.compact.join("\n")
13
+ options = UniformNotifier.console.is_a?(Hash) ? UniformNotifier.console : {}
14
+ script_attributes = options[:attributes] || {}
11
15
 
12
- code = <<-CODE
13
- if (typeof(console) !== 'undefined' && console.log) {
14
- if (console.groupCollapsed && console.groupEnd) {
15
- console.groupCollapsed(#{"Uniform Notifier".inspect});
16
- console.log(#{message.inspect});
17
- console.groupEnd();
18
- } else {
19
- console.log(#{message.inspect});
20
- }
21
- }
22
- CODE
16
+ code = <<~CODE
17
+ if (typeof(console) !== 'undefined' && console.log) {
18
+ if (console.groupCollapsed && console.groupEnd) {
19
+ console.groupCollapsed(#{'Uniform Notifier'.inspect});
20
+ console.log(#{message.inspect});
21
+ console.groupEnd();
22
+ } else {
23
+ console.log(#{message.inspect});
24
+ }
25
+ }
26
+ CODE
23
27
 
24
- wrap_js_association code
28
+ wrap_js_association code, script_attributes
25
29
  end
26
30
  end
27
31
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class RailsLogger < Base
3
5
  def self.active?
@@ -6,7 +8,7 @@ class UniformNotifier
6
8
 
7
9
  protected
8
10
 
9
- def self._out_of_channel_notify( data )
11
+ def self._out_of_channel_notify(data)
10
12
  message = data.values.compact.join("\n")
11
13
 
12
14
  Rails.logger.warn message
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class Raise < Base
3
5
  def self.active?
4
- @exception_class
6
+ defined?(@exception_class)
5
7
  end
6
8
 
7
9
  def self.setup_connection(exception_class)
@@ -10,7 +12,7 @@ class UniformNotifier
10
12
 
11
13
  protected
12
14
 
13
- def self._out_of_channel_notify( data )
15
+ def self._out_of_channel_notify(data)
14
16
  message = data.values.compact.join("\n")
15
17
 
16
18
  raise @exception_class, message
@@ -1,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class RollbarNotifier < Base
5
+ DEFAULT_LEVEL = 'info'
6
+
3
7
  def self.active?
4
8
  !!UniformNotifier.rollbar
5
9
  end
@@ -10,7 +14,10 @@ class UniformNotifier
10
14
  message = data.values.compact.join("\n")
11
15
 
12
16
  exception = Exception.new(message)
13
- Rollbar.info(exception)
17
+ level = UniformNotifier.rollbar.fetch(:level, DEFAULT_LEVEL) if UniformNotifier.rollbar.is_a?(Hash)
18
+ level ||= DEFAULT_LEVEL
19
+
20
+ Rollbar.log(level, exception)
14
21
  end
15
22
  end
16
23
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UniformNotifier
4
+ class SentryNotifier < Base
5
+ def self.active?
6
+ !!UniformNotifier.sentry
7
+ end
8
+
9
+ protected
10
+
11
+ def self._out_of_channel_notify(data)
12
+ message = data.values.compact.join("\n")
13
+
14
+ opt = {}
15
+ opt = UniformNotifier.sentry if UniformNotifier.sentry.is_a?(Hash)
16
+
17
+ exception = Exception.new(message)
18
+ Raven.capture_exception(exception, opt)
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class Slack < Base
3
- POSSIBLE_OPTIONS = [:username, :channel]
5
+ POSSIBLE_OPTIONS = %i[username channel].freeze
4
6
 
5
7
  @slack = nil
6
8
 
@@ -9,43 +11,39 @@ class UniformNotifier
9
11
  @slack
10
12
  end
11
13
 
12
- def setup_connection(config={})
14
+ def setup_connection(config = {})
13
15
  webhook_url, options = parse_config(config)
14
16
  fail_connection('webhook_url required for Slack notification') unless webhook_url
15
17
 
16
18
  require 'slack-notifier'
17
19
  @slack = ::Slack::Notifier.new webhook_url, options
18
20
  rescue LoadError
19
- fail_connection 'You must install the slack-notifier gem to use Slack notification: '\
20
- '`gem install slack-notifier`'
21
+ fail_connection 'You must install the slack-notifier gem to use Slack notification: `gem install slack-notifier`'
21
22
  end
22
23
 
23
24
  protected
24
25
 
25
- def _out_of_channel_notify(data)
26
- message = data.values.compact.join("\n")
27
- notify(message)
28
- end
26
+ def _out_of_channel_notify(data)
27
+ message = data.values.compact.join("\n")
28
+ notify(message)
29
+ end
29
30
 
30
31
  private
31
32
 
32
- def fail_connection(message)
33
- @slack = nil
34
- raise NotificationError.new(message)
35
- end
36
-
37
- def notify(message)
38
- @slack.ping message
39
- end
33
+ def fail_connection(message)
34
+ @slack = nil
35
+ raise NotificationError, message
36
+ end
40
37
 
41
- def parse_config(config)
42
- options = config.select do |name, value|
43
- POSSIBLE_OPTIONS.include?(name) && !value.nil?
44
- end
38
+ def notify(message)
39
+ @slack.ping message
40
+ end
45
41
 
46
- return config[:webhook_url], options
47
- end
42
+ def parse_config(config)
43
+ options = config.select { |name, value| POSSIBLE_OPTIONS.include?(name) && !value.nil? }
48
44
 
45
+ [config[:webhook_url], options]
46
+ end
49
47
  end
50
48
  end
51
49
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UniformNotifier
4
+ class TerminalNotifier < Base
5
+ def self.active?
6
+ !!UniformNotifier.terminal_notifier
7
+ end
8
+
9
+ protected
10
+
11
+ def self._out_of_channel_notify(data)
12
+ unless defined?(::TerminalNotifier)
13
+ begin
14
+ require 'terminal-notifier'
15
+ rescue LoadError
16
+ raise NotificationError,
17
+ 'You must install the terminal-notifier gem to use terminal_notifier: `gem install terminal-notifier`'
18
+ end
19
+ end
20
+
21
+ ::TerminalNotifier.notify(data[:body], title: data[:title])
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
- VERSION = "1.10.0"
4
+ VERSION = '1.13.1'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class Xmpp < Base
3
5
  @receiver = nil
@@ -8,7 +10,7 @@ class UniformNotifier
8
10
  @xmpp
9
11
  end
10
12
 
11
- def self.setup_connection( xmpp_information )
13
+ def self.setup_connection(xmpp_information)
12
14
  return unless xmpp_information
13
15
 
14
16
  require 'xmpp4r'
@@ -16,43 +18,42 @@ class UniformNotifier
16
18
  @xmpp = xmpp_information
17
19
  @receiver = xmpp_information[:receiver]
18
20
  @password = xmpp_information[:password]
19
- @account = xmpp_information[:account]
21
+ @account = xmpp_information[:account]
20
22
  @show_online_status = xmpp_information[:show_online_status]
21
23
  @stay_connected = xmpp_information[:stay_connected].nil? ? true : xmpp_information[:stay_connected]
22
24
 
23
25
  connect if @stay_connected
24
26
  rescue LoadError
25
27
  @xmpp = nil
26
- raise NotificationError.new( 'You must install the xmpp4r gem to use XMPP notification: `gem install xmpp4r`' )
28
+ raise NotificationError, 'You must install the xmpp4r gem to use XMPP notification: `gem install xmpp4r`'
27
29
  end
28
30
 
29
31
  protected
30
32
 
31
- def self._out_of_channel_notify( data )
33
+ def self._out_of_channel_notify(data)
32
34
  message = data.values.compact.join("\n")
33
35
 
34
- notify( message )
36
+ notify(message)
35
37
  end
36
38
 
37
39
  private
38
- def self.connect
39
- jid = Jabber::JID.new( @account )
40
- @xmpp = Jabber::Client.new( jid )
41
- @xmpp.connect
42
- @xmpp.auth( @password )
43
- @xmpp.send( presence_status ) if @show_online_status
44
- end
45
-
46
- def self.notify( message )
47
- connect unless @stay_connected
48
- message = Jabber::Message.new( @receiver, message ).
49
- set_type( :normal ).
50
- set_subject( 'Uniform Notifier' )
51
- @xmpp.send( message )
52
- end
53
-
54
- def self.presence_status
55
- Jabber::Presence.new.set_status( "Uniform Notifier started on #{Time.now}" )
56
- end
40
+
41
+ def self.connect
42
+ jid = Jabber::JID.new(@account)
43
+ @xmpp = Jabber::Client.new(jid)
44
+ @xmpp.connect
45
+ @xmpp.auth(@password)
46
+ @xmpp.send(presence_status) if @show_online_status
47
+ end
48
+
49
+ def self.notify(message)
50
+ connect unless @stay_connected
51
+ message = Jabber::Message.new(@receiver, message).set_type(:normal).set_subject('Uniform Notifier')
52
+ @xmpp.send(message)
53
+ end
54
+
55
+ def self.presence_status
56
+ Jabber::Presence.new.set_status("Uniform Notifier started on #{Time.now}")
57
+ end
57
58
  end
58
59
  end