uniform_notifier 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -1
  3. data/Gemfile +3 -1
  4. data/README.md +18 -1
  5. data/Rakefile +13 -11
  6. data/lib/uniform_notifier.rb +8 -7
  7. data/lib/uniform_notifier/airbrake.rb +2 -0
  8. data/lib/uniform_notifier/base.rb +17 -14
  9. data/lib/uniform_notifier/bugsnag.rb +5 -3
  10. data/lib/uniform_notifier/customized_logger.rb +6 -4
  11. data/lib/uniform_notifier/errors.rb +3 -1
  12. data/lib/uniform_notifier/growl.rb +23 -20
  13. data/lib/uniform_notifier/honeybadger.rb +2 -0
  14. data/lib/uniform_notifier/javascript_alert.rb +7 -3
  15. data/lib/uniform_notifier/javascript_console.rb +18 -14
  16. data/lib/uniform_notifier/rails_logger.rb +3 -1
  17. data/lib/uniform_notifier/raise.rb +3 -1
  18. data/lib/uniform_notifier/rollbar.rb +2 -0
  19. data/lib/uniform_notifier/sentry.rb +2 -0
  20. data/lib/uniform_notifier/slack.rb +20 -19
  21. data/lib/uniform_notifier/terminal_notifier.rb +23 -0
  22. data/lib/uniform_notifier/version.rb +3 -1
  23. data/lib/uniform_notifier/xmpp.rb +26 -23
  24. data/spec/spec_helper.rb +8 -6
  25. data/spec/uniform_notifier/airbrake_spec.rb +12 -10
  26. data/spec/uniform_notifier/base_spec.rb +10 -8
  27. data/spec/uniform_notifier/bugsnag_spec.rb +21 -19
  28. data/spec/uniform_notifier/customized_logger_spec.rb +9 -7
  29. data/spec/uniform_notifier/growl_spec.rb +19 -18
  30. data/spec/uniform_notifier/honeybadger_spec.rb +12 -10
  31. data/spec/uniform_notifier/javascript_alert_spec.rb +29 -9
  32. data/spec/uniform_notifier/javascript_console_spec.rb +55 -17
  33. data/spec/uniform_notifier/rails_logger_spec.rb +9 -7
  34. data/spec/uniform_notifier/raise_spec.rb +13 -11
  35. data/spec/uniform_notifier/rollbar_spec.rb +8 -6
  36. data/spec/uniform_notifier/sentry_spec.rb +12 -10
  37. data/spec/uniform_notifier/slack_spec.rb +10 -8
  38. data/spec/uniform_notifier/terminal_notifier_spec.rb +25 -0
  39. data/spec/uniform_notifier/xmpp_spec.rb +17 -15
  40. data/uniform_notifier.gemspec +18 -17
  41. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: daf1fcd71af2c468e1ba0fe5173fac2205bae8dd
4
- data.tar.gz: c97aeac72e004d585fba564dc09fbc408d5af426
3
+ metadata.gz: f27b211c1e550787b74d7a57a1f534fda78a5271
4
+ data.tar.gz: 052c8e0d80a431a89c71d5578c0603fd5609686f
5
5
  SHA512:
6
- metadata.gz: 23fe312e299e387bba4da21216ad2e0c5dd87e92c032fed14fb5fedd210c21c7a925be46cdfb7a1056609b4493fc17de29fa1c00c9581b970510f9780d8ffd30
7
- data.tar.gz: 00446377e262d875c05f5fb78ec8086c9502559e908909243c965687f17abe7bd27f7b586b5a5ab6b17f6ba8038ceb42a1300b98c01d394941f87e2e634f1c65
6
+ metadata.gz: 925e6cf2f2dfc20a84fef57e1bee9872d5ddb18396142b63e335f9db5fe275650a3def097a6a2688e7411ffe2dd980be1313b5271e577514193f9faf0f2f071b
7
+ data.tar.gz: 2056c09e18698a84e87f4c8029fea3c73643c7ded92af0f30a40c79edb58b02721a88517012183ebf76f1f6f829150307e3e594151c234fb9e2a438b1feb9eab
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Next Release
2
2
 
3
- ## 1.11.0 (13/11/2017)
3
+ ## 1.12.0 (08/17/2018)
4
+
5
+ * Add [terminal-notifier](https://github.com/julienXX/terminal-notifier) support
6
+ * Lots of refactors from Awesome Code
7
+
8
+ ## 1.11.0 (11/13/2017)
4
9
 
5
10
  * Add Sentry notifier
6
11
 
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source "http://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in uniform_notifier.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # UniformNotifier
2
2
 
3
+ [![Build
4
+ Status](https://secure.travis-ci.org/flyerhzm/uniform_notifier.png)](http://travis-ci.org/flyerhzm/uniform_notifier)
5
+ [![AwesomeCode Status for flyerhzm/uniform_notifier](https://awesomecode.io/projects/3e29a7de-0b37-4ecf-b06d-410ebf815174/status)](https://awesomecode.io/projects/32)
6
+
3
7
  uniform_notifier is extracted from [bullet][0], it gives you the ability to send notification through rails logger, customized logger, javascript alert, javascript console, growl, xmpp, airbrake and honeybadger.
4
8
 
5
9
  ## Install
@@ -40,11 +44,15 @@ if you want to notify by slack, you should install slack-notifier first
40
44
 
41
45
  gem install slack-notifier
42
46
 
47
+ if you want to notify by terminal-notifier, you must install it first
48
+
49
+ gem install terminal-notifier
50
+
43
51
  ### add it into Gemfile (Bundler)
44
52
 
45
53
  gem "uniform_notifier"
46
54
 
47
- you should add ruby-growl, ruby_gntp, xmpp4r, airbrake, bugsnag, honeybadger, slack-notifier gem if you want.
55
+ you should add ruby-growl, ruby_gntp, xmpp4r, airbrake, bugsnag, honeybadger, slack-notifier, terminal-notifier gem if you want.
48
56
 
49
57
  ## Usage
50
58
 
@@ -56,9 +64,15 @@ By default, all notifiers are disabled, you should enable them first.
56
64
 
57
65
  # javascript alert
58
66
  UniformNotifier.alert = true
67
+ # javascript alert with options
68
+ # the attributes key adds custom attributes to the script tag appended to the body
69
+ UniformNotifier.alert = { :attributes => { :nonce => 'mySecret-nonce', 'data-key' => 'value' } }
59
70
 
60
71
  # javascript console (Safari/Webkit browsers or Firefox w/Firebug installed)
61
72
  UniformNotifier.console = true
73
+ # javascript console with options
74
+ # the attributes key adds custom attributes to the script tag appended to the body
75
+ UniformNotifier.console = { :attributes => { :nonce => 'mySecret-nonce', 'data-key' => 'value' } }
62
76
 
63
77
  # rails logger
64
78
  UniformNotifier.rails_logger = true
@@ -105,6 +119,9 @@ By default, all notifiers are disabled, you should enable them first.
105
119
  :receiver => 'recipient_account@jabber.org',
106
120
  :show_online_status => true }
107
121
 
122
+ # terminal-notifier
123
+ UniformNotifier.terminal_notifier = true
124
+
108
125
  # raise an error
109
126
  UniformNotifier.raise = true # raise a generic exception
110
127
 
data/Rakefile CHANGED
@@ -1,25 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler'
2
4
  Bundler::GemHelper.install_tasks
3
5
 
4
- require "rake"
5
- require "rdoc/task"
6
- require "rspec"
7
- require "rspec/core/rake_task"
6
+ require 'rake'
7
+ require 'rdoc/task'
8
+ require 'rspec'
9
+ require 'rspec/core/rake_task'
8
10
 
9
11
  RSpec::Core::RakeTask.new(:spec) do |spec|
10
- spec.pattern = "spec/**/*_spec.rb"
12
+ spec.pattern = 'spec/**/*_spec.rb'
11
13
  end
12
14
 
13
15
  RSpec::Core::RakeTask.new('spec:progress') do |spec|
14
- spec.rspec_opts = %w(--format progress)
15
- spec.pattern = "spec/**/*_spec.rb"
16
+ spec.rspec_opts = %w[--format progress]
17
+ spec.pattern = 'spec/**/*_spec.rb'
16
18
  end
17
19
 
18
20
  Rake::RDocTask.new do |rdoc|
19
- rdoc.rdoc_dir = "rdoc"
21
+ rdoc.rdoc_dir = 'rdoc'
20
22
  rdoc.title = "uniform_notifier #{UniformNotifier::VERSION}"
21
- rdoc.rdoc_files.include("README*")
22
- rdoc.rdoc_files.include("lib/**/*.rb")
23
+ rdoc.rdoc_files.include('README*')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
25
  end
24
26
 
25
- task :default => :spec
27
+ task default: :spec
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uniform_notifier/base'
2
4
  require 'uniform_notifier/errors'
3
5
  require 'uniform_notifier/javascript_alert'
@@ -13,17 +15,16 @@ require 'uniform_notifier/rollbar'
13
15
  require 'uniform_notifier/bugsnag'
14
16
  require 'uniform_notifier/slack'
15
17
  require 'uniform_notifier/raise'
18
+ require 'uniform_notifier/terminal_notifier'
16
19
 
17
20
  class UniformNotifier
18
- AVAILABLE_NOTIFIERS = [:alert, :console, :growl, :honeybadger, :xmpp, :rails_logger,
19
- :customized_logger, :airbrake, :rollbar, :bugsnag, :slack, :raise,
20
- :sentry
21
- ]
21
+ AVAILABLE_NOTIFIERS = %i[alert console growl honeybadger xmpp rails_logger
22
+ customized_logger airbrake rollbar bugsnag slack raise
23
+ sentry terminal_notifier].freeze
22
24
 
23
25
  NOTIFIERS = [JavascriptAlert, JavascriptConsole, Growl, HoneybadgerNotifier, Xmpp, RailsLogger,
24
26
  CustomizedLogger, AirbrakeNotifier, RollbarNotifier, BugsnagNotifier, Raise, Slack,
25
- SentryNotifier
26
- ]
27
+ SentryNotifier, TerminalNotifier].freeze
27
28
 
28
29
  class NotificationError < StandardError; end
29
30
 
@@ -31,7 +32,7 @@ class UniformNotifier
31
32
  attr_accessor(*AVAILABLE_NOTIFIERS)
32
33
 
33
34
  def active_notifiers
34
- NOTIFIERS.select { |notifier| notifier.active? }
35
+ NOTIFIERS.select(&:active?)
35
36
  end
36
37
 
37
38
  undef :growl=
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class AirbrakeNotifier < Base
3
5
  def self.active?
@@ -1,40 +1,43 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class Base
3
5
  def self.active?
4
6
  false
5
7
  end
6
8
 
7
- def self.inline_notify( data )
9
+ def self.inline_notify(data)
8
10
  return unless active?
9
11
 
10
12
  # For compatibility to the old protocol
11
- data = { :title => data } if data.is_a?(String)
13
+ data = { title: data } if data.is_a?(String)
12
14
 
13
- _inline_notify( data )
15
+ _inline_notify(data)
14
16
  end
15
17
 
16
- def self.out_of_channel_notify( data )
18
+ def self.out_of_channel_notify(data)
17
19
  return unless active?
18
20
 
19
21
  # For compatibility to the old protocol
20
- data = { :title => data } if data.is_a?(String)
22
+ data = { title: data } if data.is_a?(String)
21
23
 
22
24
  _out_of_channel_notify(data)
23
25
  end
24
26
 
25
27
  protected
26
28
 
27
- def self._inline_notify( data )
28
- end
29
+ def self._inline_notify(data); end
29
30
 
30
- def self._out_of_channel_notify( data )
31
- end
31
+ def self._out_of_channel_notify(data); end
32
+
33
+ def self.wrap_js_association(code, attributes = {})
34
+ attributes = { type: 'text/javascript' }.merge(attributes || {})
35
+ attributes_string = attributes.map { |k, v| "#{k}=#{v.to_s.inspect}" }.join(' ')
32
36
 
33
- def self.wrap_js_association( code )
34
- <<-CODE
35
- <script type="text/javascript">/*<![CDATA[*/
36
- #{code}
37
- /*]]>*/</script>
37
+ <<~CODE
38
+ <script #{attributes_string}>/*<![CDATA[*/
39
+ #{code}
40
+ /*]]>*/</script>
38
41
  CODE
39
42
  end
40
43
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UniformNotifier
2
4
  class BugsnagNotifier < Base
3
5
  def self.active?
@@ -15,9 +17,9 @@ class UniformNotifier
15
17
  exception = Exception.new(data[:title])
16
18
  exception.set_backtrace(data[:backtrace]) if data[:backtrace]
17
19
  Bugsnag.notify(exception, opt.merge(
18
- :grouping_hash => data[:body] || data[:title],
19
- :notification => data
20
- ))
20
+ grouping_hash: data[:body] || data[:title],
21
+ notification: data
22
+ ))
21
23
  end
22
24
  end
23
25
  end
@@ -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,18 +8,18 @@ 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, '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
19
  end
18
20
  end
19
21
 
20
- def self.setup_connection_growl( growl )
22
+ def self.setup_connection_growl(growl)
21
23
  return unless growl
22
24
  require 'ruby-growl'
23
25
  if growl.instance_of?(Hash)
@@ -33,7 +35,7 @@ class UniformNotifier
33
35
  notify 'Uniform Notifier Growl has been turned on' if !growl.instance_of?(Hash) || !growl[:quiet]
34
36
  end
35
37
 
36
- def self.setup_connection_gntp( growl )
38
+ def self.setup_connection_gntp(growl)
37
39
  return unless growl
38
40
  require 'ruby_gntp'
39
41
  if growl.instance_of?(Hash)
@@ -43,33 +45,34 @@ class UniformNotifier
43
45
  @password ||= nil
44
46
  @host ||= 'localhost'
45
47
  @growl = GNTP.new('uniform_notifier', @host, @password, 23053)
46
- @growl.register({:notifications => [{
47
- :name => 'uniform_notifier',
48
- :enabled => true,
49
- }]})
48
+ @growl.register(notifications: [{
49
+ name: 'uniform_notifier',
50
+ enabled: true,
51
+ }])
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(
71
+ name: 'uniform_notifier',
72
+ title: 'Uniform Notifier',
73
+ text: message
74
+ )
73
75
  end
76
+ end
74
77
  end
75
78
  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?
@@ -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