bellman 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: c3fbd1ee19a3727dfb7efd00bafd2de608cc08c7cecffbaa311a2f0ad71c51d9
4
- data.tar.gz: 853afcf30bffdbbf08d6b81192725543650ddad687e6ed8645fa70082887f645
3
+ metadata.gz: c65c02d5ddc7dc46aba77a42fc162c5f35b77bba264a990cc5c66580fd5bd397
4
+ data.tar.gz: 484d19f9b7546a31599afef4184ecff5a9ef43e24bd6dd46294c532a02707815
5
5
  SHA512:
6
- metadata.gz: caf2124a78105f6eae4e0bb82599febb623411405bb4c87ec15e001ceeb57b400655e42330c657020f29031992be1327b17995b6aea484e75251e46a08621542
7
- data.tar.gz: 770d99680d228da731033197bc7108b905904b3a56865c5f4ce5c514be950c71b8c235393e444dbce09590cad60b014b3bf4a3203ecedc7f2cdb86195cf6d5a6
6
+ metadata.gz: '03491319b209b2994b3329c12aafa4aba3ea3b09bb3046aff6cfc4d0899797748f591384ddc3b6e2df713a00bc7e6921c1b44ef1aa7e2c64d79d6d8a4bf2e2bb'
7
+ data.tar.gz: 80961f465408e2880701fc8f41f9a21157fa989da5c6d2231f8c53b891bea76ede01177d464c3eaa3962191a028b16e9168cd1f34e30f0de62abfc02ed435918
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bellman (0.1.1)
4
+ bellman (0.1.2)
5
5
  activerecord (> 4.2.0)
6
6
  activesupport (> 4.2.0)
7
7
 
data/README.md CHANGED
@@ -81,6 +81,12 @@ For example, here is a common configuration for when an application uses the Rai
81
81
  ```ruby
82
82
  Bellman.configure do |config|
83
83
  config.default_severity = :error
84
+
85
+ # Anything other than :raise will set the severity level to the default
86
+ # severity if an unkown one is past. By default Bellman will raise an error
87
+ # so that you can catch your mistakes in development
88
+ config.on_unknown_severity = :raise
89
+
84
90
  config.handlers = [
85
91
  {
86
92
  id: :log,
@@ -19,6 +19,7 @@ module Bellman
19
19
  # Set the defaults
20
20
  config.severities = %i[debug info warn error fatal].freeze
21
21
  config.default_severity = :error
22
+ config.on_unknown_severity = :raise
22
23
  config.handlers = [
23
24
  {
24
25
  id: :log,
@@ -38,12 +39,12 @@ module Bellman
38
39
  @handler = Handlers::Handler.new
39
40
  end
40
41
 
41
- def self.handler
42
- @handler
43
- end
44
-
45
- def self.error_handler(id:)
46
- @handler.handlers.find { |hndlr| hndlr[:id] == id.to_sym }
42
+ def self.handler(id: nil)
43
+ if id.nil?
44
+ @handler
45
+ else
46
+ @handler.handlers.find { |hndlr| hndlr[:id] == id.to_sym }
47
+ end
47
48
  end
48
49
 
49
50
  # rubocop:disable Metrics/ParameterLists
@@ -14,10 +14,8 @@ module Bellman
14
14
  # rubocop:disable Metrics/ParameterLists
15
15
  def handle(error, severity: :error, trace_id: nil, objects: nil,
16
16
  data: nil, include_backtrace: false, handlers: nil)
17
- unless Bellman.config.severities.include?(severity)
18
- severity = Bellman.config.default_severity
19
- end
20
17
 
18
+ severity = handle_severity(severity)
21
19
  handlers = if handlers.present?
22
20
  process_handlers_config(handlers)
23
21
  else
@@ -43,6 +41,16 @@ module Bellman
43
41
 
44
42
  private
45
43
 
44
+ def handle_severity(severity)
45
+ return severity if Bellman.config.severities.include?(severity)
46
+ if Bellman.config.on_unknown_severity != :raise
47
+ return Bellman.config.default_severity
48
+ end
49
+
50
+ raise "Unknown severity level #{severity}. " \
51
+ "Must be one of #{Bellman.config.severities}"
52
+ end
53
+
46
54
  def process_handlers_config(configs)
47
55
  configs.map { |config| process_handler_config(config) }
48
56
  end
@@ -68,7 +76,7 @@ module Bellman
68
76
  config[:class].new(**config[:params])
69
77
  end
70
78
  elsif config[:id]
71
- config = Bellman.error_handler(config[:id])
79
+ config = Bellman.handler(config[:id])
72
80
  config[:handler] = if config[:params].blank?
73
81
  config[:class].new
74
82
  else
@@ -88,12 +96,12 @@ module Bellman
88
96
 
89
97
  case config
90
98
  when Symbol
91
- handler = Bellman.error_handler(id: config)
99
+ handler = Bellman.handler(id: config)
92
100
  return handler if handler
93
101
  when String
94
102
  # If the string matches the ID of a handler defined in the Bellman
95
103
  # default config, return that.
96
- handler = Bellman.error_handler(id: config.to_sym)
104
+ handler = Bellman.handler(id: config.to_sym)
97
105
  return handler if handler
98
106
 
99
107
  # rubocop:disable Lint/SuppressedException
@@ -47,9 +47,21 @@ module Bellman
47
47
  private
48
48
 
49
49
  def set_sentry_context(scope, objects)
50
+ # We are organizing the objects by class so that we can send the data
51
+ # on a per class basis. Note, we cannot just loop over the objects
52
+ # if we are using the class name as the key since this would mean that
53
+ # any time there are multiple objects of the same type, we'd only send
54
+ # the data for the last one as it would overwrite the data.
55
+ h = {}
50
56
  objects.each do |object|
57
+ key = object.class.name
58
+ h[key] = [] unless h.key?(key)
59
+ h[key] << object
60
+ end
61
+
62
+ h.each do |key, obj_array|
51
63
  scope.set_context(
52
- object.class.name, { id: object.id }
64
+ key, { ids: obj_array.map(&:id) }
53
65
  )
54
66
  end
55
67
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bellman
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bellman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick R. Schmid