talk-notifier 1.0.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84ac79987e8da4eaa1e0c3aa291bafe91ce3271f
4
- data.tar.gz: 0e3da3d5c2a9b27bf61117d4a104c54bbb03d557
3
+ metadata.gz: 9b2d7e1e5ce60d32b1422c83e56b19c2cd5438b8
4
+ data.tar.gz: 337212f25be65b6280ff877b2d86416e4bbd7508
5
5
  SHA512:
6
- metadata.gz: 34c6de2fe1eee2e1a10df93ecfac6b45f0f42f70c6ff3df50c8bb7a1f62ae0ff170ec6db8ff67a99f1c37b63b91ec2da19a49d1445b7f1bf91ea725994820582
7
- data.tar.gz: 2538225cc39d23f49ef71760176569b4ab1229c2a5ed9edbaeb27ce106a227a7af11b72d43f4d406ac31be263b8ec0a53dd0be1c8d9028462be7246f395ddaf5
6
+ metadata.gz: 80265fc627645229368b4990905001e885392af321fcf283fdf2f57b39477c4e7a04266f81eb7a87d95ceeca7003b5ca2e61477bbee2c897b2397c3d30bf4dbf
7
+ data.tar.gz: 75beddf531c91f784ae8af79d1c68c0fc44c4d7d3a6fae551752383da30b322fcfb0645f9f22df963530bfd3e6acfa0205c0f858fe16d16d42725c67e89406fa
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Talk::Notifier
1
+ # ExceptionNotifier::TalkNotifier
2
2
 
3
- Notify exceptions using Talk.
3
+ Notify exceptions using [Talk](http://jianliao.com).
4
4
 
5
5
  ## Installation
6
6
 
@@ -23,12 +23,15 @@ Or install it yourself as:
23
23
  Add following lines to your `exception-notification` configurations.
24
24
 
25
25
  ```ruby
26
- Rails.application.config.middleware.use ExceptionNotification::Rack,
27
- :talk => {
28
- author_name: 'something you like', # message author name
29
- hook_url: 'your hook url', # your hook url
30
- backtrace_depth: 10, # (optional) backtrace depth you want, default 10
31
- }
26
+ Rails.application.config.middleware.use(
27
+ ExceptionNotification::Rack,
28
+ :talk => {
29
+ hook_url: 'your hook url', # your webhook url
30
+ author_name: 'something you like', # (optional) author name, default hostname
31
+ backtrace_depth: 10, # (optional) backtrace depth you want, nil if you want full backtrace, default nil
32
+ clean_backtrace: false, # (optional) whether or not to clean backtrace using Rails::BacktraceCleaner, default false
33
+ }
34
+ )
32
35
  ```
33
36
 
34
37
  ## Contributing
@@ -1,10 +1,14 @@
1
1
  require 'faraday'
2
+ require 'socket'
2
3
 
3
4
  module ExceptionNotifier
4
5
  class TalkNotifier
6
+ include BacktraceCleaner
7
+
5
8
  def initialize(options)
6
- @author_name = options[:author_name]
7
- @backtrace_depth = options[:backtrace_depth] || 10
9
+ @author_name = options[:author_name] || Socket.gethostname
10
+ @backtrace_depth = options[:backtrace_depth]
11
+ @clean_backtrace = options[:clean_backtrace]
8
12
  @hook_url = options[:hook_url]
9
13
  end
10
14
 
@@ -12,8 +16,18 @@ module ExceptionNotifier
12
16
  Faraday.post(@hook_url, {
13
17
  authorName: @author_name,
14
18
  title: "#{exception.class.name}: #{exception.message}",
15
- text: exception.backtrace.try(:[], 0, @backtrace_depth).try(:join, "\n")
19
+ text: stringify_exception(exception)
16
20
  })
17
21
  end
22
+
23
+ def stringify_exception(e)
24
+ if e.backtrace.present?
25
+ backtrace = @clean_backtrace ? clean_backtrace(e) : e.backtrace
26
+ backtrace = backtrace.first(@backtrace_depth) if @backtrace_depth
27
+ ["#{e.class.name}: #{e.message}", 'Backtrace: ', backtrace].join("\n")
28
+ else
29
+ "#{e.class.name}: #{e.message}"
30
+ end
31
+ end
18
32
  end
19
33
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'talk-notifier'
7
- spec.version = '1.0.0'
7
+ spec.version = '1.0.1'
8
8
  spec.authors = ['于湛']
9
9
  spec.email = ['yuzhan1994@gmail.com']
10
10
 
@@ -16,5 +16,5 @@ Gem::Specification.new do |spec|
16
16
  spec.require_paths = ['lib']
17
17
 
18
18
  spec.add_dependency 'exception_notification', '~> 4.0'
19
- spec.add_dependency 'faraday', '~> 0.9.0'
19
+ spec.add_dependency 'faraday', '~> 0.9', '>= 0.8.0'
20
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: talk-notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "于湛"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-29 00:00:00.000000000 Z
11
+ date: 2016-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: exception_notification
@@ -30,14 +30,20 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.0
33
+ version: '0.9'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 0.8.0
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
41
  - - "~>"
39
42
  - !ruby/object:Gem::Version
40
- version: 0.9.0
43
+ version: '0.9'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.8.0
41
47
  description:
42
48
  email:
43
49
  - yuzhan1994@gmail.com