exception_transformer 0.1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7ed6231e5c5ec775142f9bcbefbf8e5611491f11ca8210d97bd883a3f91f494
4
- data.tar.gz: 8e676ba345439a39b6b36cf1139e2554127d4f1d8842982c115f7aa0ec85f982
3
+ metadata.gz: e002579e12b51a59b8338e72c12566a91c0e055eafb2fa85702c73e7bcfa8fbe
4
+ data.tar.gz: 8fac9ece73ba9a952ef55f50f2e09a438cc8a727a1eceb8e91b699a3467687a8
5
5
  SHA512:
6
- metadata.gz: 495784ad163c57718c3d7ea4891937a5e2f909fefe4d9d6c6396da0663ec160d63570999e4adfb9447ec39bb9a0112d8b9f9c9dcbfc990a6994a72cf01136ff3
7
- data.tar.gz: 4e2fabcfccd2915c81ece88e93aa20b6f9eb70fc20541d3597762bcc28307707b21276f3042d35bd95e5e9a7323d46d52ffee4580a532c4075d3c1ab8b9fbb9c
6
+ metadata.gz: 716c969b405cde7f650f5ea40c5d2370655b9f23340fac8c382568f0abc58cbd5a769049182fdfbb83960da929636401cd3229768248956c86be704f9fcf2983
7
+ data.tar.gz: 07fb3bb2b259f297eb6eb56acc982c3dfefd1a245902f6bb2f6907728935493b41b04c976dbc12078d09030e0110bdfb473fe986b08e9ad857bd0ac42dbd3cf2
@@ -1,17 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'exception_transformer/version'
4
+ require 'exception_transformer/config'
2
5
  require 'exception_transformer/transformer'
6
+ require 'exception_transformer/reportable'
3
7
 
4
8
  require 'active_support'
5
9
  require 'active_support/core_ext'
6
10
 
7
- require 'byebug'
8
-
9
11
  module ExceptionTransformer
12
+ attr_accessor :config
13
+
10
14
  def self.included base
11
15
  base.send :include, InstanceMethods
12
16
  base.extend ClassMethods
13
17
  end
14
18
 
19
+ # To send exceptions to a crash reporter, implement a configuration block:
20
+ # @example
21
+ # ExceptionTransformer.configure do |config|
22
+ # config.reporter = proc { |e| Raven.capture_exception(e) }
23
+ # end
24
+ def self.configure
25
+ yield config if block_given?
26
+ end
27
+
28
+ def self.config
29
+ @config ||= Config.new
30
+ end
31
+
15
32
  module ClassMethods
16
33
  # Add exceptions to be transformed in `handle_exceptions` block.
17
34
  # @examples
@@ -67,6 +84,7 @@ module ExceptionTransformer
67
84
  def handle_exceptions(group = :default, **opts)
68
85
  # NOTE: `base_label` returns the label of this frame without decoration,
69
86
  # i.e. if `label` was 'block in test', then `base_label` would be `test`.
87
+
70
88
  calling_method = caller_locations(1, 1)[0].base_label
71
89
  transformer = self.class.find_exception_transformer(group)
72
90
 
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ExceptionTransformer::Config
4
+ attr_accessor :reporter
5
+
6
+ def initialize
7
+ self.reporter ||= proc { |e| }
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ExceptionTransformer
2
4
  # Include this module when declaring an exception class to add
3
5
  # the `reportable?` flag to individual exceptions. The presence
@@ -27,7 +29,7 @@ module ExceptionTransformer
27
29
  module ClassMethods
28
30
  # Returns a subclass 'Reportable_<name>' of the current class that
29
31
  # includes `Reportable`. This subclass is created the first time
30
- # time this method is called and reused for subsequent invocations.
32
+ # this method is called and reused for subsequent invocations.
31
33
  def as_reportable
32
34
  return self if self <= ReportableException
33
35
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ExceptionTransformer::Transformer
2
4
  attr_accessor :strategy, :validator, :delegate, :mappings
3
5
 
@@ -83,8 +85,7 @@ class ExceptionTransformer::Transformer
83
85
  yield
84
86
  rescue => e
85
87
  unless e.respond_to?(:reportable?) && !e.reportable?
86
- # @examples
87
- # Raven.capture_exception(e)
88
+ ExceptionTransformer.config.reporter.call(e)
88
89
  end
89
90
 
90
91
  raise
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ExceptionTransformer
2
- VERSION = "0.1.0"
4
+ VERSION = "1.0.1"
3
5
  end
@@ -1,4 +1,4 @@
1
- require 'exception_transformer'
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe ExceptionTransformer do
4
4
  class FooError < StandardError; end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ClassHelpers
2
4
  # Defines a named class, descending from `super_class`.
3
5
  # The constant assigned to the the class will be restored
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_transformer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick McLaren
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-01-29 00:00:00.000000000 Z
12
+ date: 2019-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -53,20 +53,6 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '3.0'
56
- - !ruby/object:Gem::Dependency
57
- name: byebug
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '10.0'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '10.0'
70
56
  - !ruby/object:Gem::Dependency
71
57
  name: activesupport
72
58
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +67,7 @@ dependencies:
81
67
  - - "~>"
82
68
  - !ruby/object:Gem::Version
83
69
  version: '5.0'
84
- description: Add exceptions to be transformed.
70
+ description: Transform exceptions and send to a crash reporter.
85
71
  email:
86
72
  - patrick@privy.com
87
73
  - allina@privy.com
@@ -90,6 +76,7 @@ extensions: []
90
76
  extra_rdoc_files: []
91
77
  files:
92
78
  - lib/exception_transformer.rb
79
+ - lib/exception_transformer/config.rb
93
80
  - lib/exception_transformer/reportable.rb
94
81
  - lib/exception_transformer/transformer.rb
95
82
  - lib/exception_transformer/version.rb
@@ -97,7 +84,7 @@ files:
97
84
  - spec/exception_transformer_spec.rb
98
85
  - spec/helpers/class_helpers.rb
99
86
  - spec/spec_helper.rb
100
- homepage: https://github.com/Privy/exception-transformer
87
+ homepage: https://github.com/Privy/exception_transformer
101
88
  licenses:
102
89
  - MIT
103
90
  metadata: {}