hbw 0.1.0 → 0.2.0

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: 820fbb36d5486bbf4f7a81e62a508992b8197513f275d257de49d636d0a4b090
4
- data.tar.gz: 72c8bbccc47e3ab5272a5cf75843cc3db8b93aaef98bf47fadcf6286a7c5bac1
3
+ metadata.gz: a07db43130bbcb0e4dad061381df31746c0f6b74c82b2fc7e28fb6196eabf056
4
+ data.tar.gz: 7dd49c10fb292b403742cf785512bf1f80cc590ecb25a45f2708395b25256692
5
5
  SHA512:
6
- metadata.gz: 8ae608412930ed3a524536c60116c61f87ae21393a826eb08b2f940efb5325b16c94938bf74436ed094f07de9a865a5b21178e28ae63af1845263b2d73981f3b
7
- data.tar.gz: 0a25eece2f08aa781c2b2ef9bbffb374cb3b2e893ff82b71939602e9d7e00685b95d9e3d3ccb1c6ac601a02296727f955a827b7d2adc42b8ec79ceba18290789
6
+ metadata.gz: 6cc47befb5635d4362d66636c9d2135f3703268cbe8ead44aad91fec698b54501d33c424336ca870c8ca3478a2d6d7b5ef86a297a25e5165bd7368e780d3241e
7
+ data.tar.gz: 20e222c9804903ef2363cb2a32c94c9a6bc79a0d41917455f4cd2a0493cd9dc9efc3ba639a005f84cd0d09e41519093569be45f686b8eb9c9dea5f5764031cf0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hbw (0.1.0)
4
+ hbw (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- By using `HBW.notify`, you can report error to honeybadger.io in production environment and raise error in development environment.
23
+ By using `HBW.notify`, you can report error to honeybadger.io if `defined?(Honeybadger)` is true and raise error if `defined?(Honeybadger)` is false.
24
24
 
25
25
  ```ruby
26
26
  HBW.notify("PaymentConfiguration", error_message, context: { company_id: self.id })
@@ -111,7 +111,7 @@ HBW.notify("PaymentConfiguration", "Empty payment period found in PaymentConfigu
111
111
 
112
112
  ### `raise_development` option
113
113
 
114
- This option is default true.
114
+ This option is default true. When `defined?(Honeybadger)` is false and `HBW.notify` is called, exception is raised by default. By setting `raise_development: false`, no exception is raised in such situation.
115
115
 
116
116
  ```ruby
117
117
  # `exception` is raised
data/lib/hbw.rb CHANGED
@@ -1,9 +1,14 @@
1
1
  require "hbw/version"
2
+ require "hbw/config"
2
3
 
3
4
  module HBW
4
5
  class ArgumentError < ::ArgumentError; end
5
6
 
7
+ @notice_only_notifier = nil
8
+
6
9
  class << self
10
+ attr_reader :notice_only_notifier
11
+
7
12
  # @overload
8
13
  #
9
14
  # @param [Exception] exception
@@ -97,11 +102,13 @@ module HBW
97
102
 
98
103
  # QA, Production
99
104
  if should_use_honeybadger?
100
- if exception_or_opts.respond_to?(:to_hash) # Already merged to opts
101
- honeybadger_notify(opts)
102
- else
103
- honeybadger_notify(exception_or_opts, opts)
104
- end
105
+ args =
106
+ if exception_or_opts.respond_to?(:to_hash) # Already merged to opts
107
+ [opts]
108
+ else
109
+ [exception_or_opts, opts]
110
+ end
111
+ notify_internal(args, notice_only: notice_only)
105
112
  return nil
106
113
  end
107
114
 
@@ -117,6 +124,14 @@ module HBW
117
124
  nil
118
125
  end
119
126
 
127
+ def configure
128
+ config = Config.new
129
+ yield(config)
130
+ if config.notice_only_api_key && should_use_honeybadger?
131
+ @notice_only_notifier = build_notifier(config.notice_only_api_key)
132
+ end
133
+ end
134
+
120
135
  private
121
136
 
122
137
  def merge_opts!(opts, error_class:, error_message:, context:, backtrace:, parameters:, action:, raise_development:, notice_only:)
@@ -137,12 +152,29 @@ module HBW
137
152
  defined?(Honeybadger)
138
153
  end
139
154
 
155
+ # @param [Array] args
156
+ def notify_internal(args, notice_only:)
157
+ if notice_only && notice_only_notifier
158
+ notice_only_notifier.notify(*args)
159
+ else
160
+ honeybadger_notify(*args)
161
+ end
162
+ end
163
+
140
164
  # @param [Exception, Hash] exception_or_opts
141
165
  # @param [Hash] opts
142
166
  def honeybadger_notify(exception_or_opts, opts = {})
143
167
  ::Honeybadger.notify(exception_or_opts, opts)
144
168
  end
145
169
 
170
+ def build_notifier(api_key)
171
+ r = ::Honeybadger::Agent.new(::Honeybadger.config.dup)
172
+ r.configure do |config|
173
+ config.api_key = api_key
174
+ end
175
+ r
176
+ end
177
+
146
178
  # @param [Exception, Hash] exception_or_opts
147
179
  # @param [Hash] opts
148
180
  # @return [String] error class
data/lib/hbw/config.rb ADDED
@@ -0,0 +1,8 @@
1
+ module HBW
2
+ class Config
3
+ def initialize
4
+ @notice_only_api_key = nil
5
+ end
6
+ attr_accessor :notice_only_api_key
7
+ end
8
+ end
data/lib/hbw/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module HBW
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hbw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nao Minami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-18 00:00:00.000000000 Z
11
+ date: 2018-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,6 +86,7 @@ files:
86
86
  - bin/setup
87
87
  - hbw.gemspec
88
88
  - lib/hbw.rb
89
+ - lib/hbw/config.rb
89
90
  - lib/hbw/version.rb
90
91
  homepage: http://github.com/south37/hbw
91
92
  licenses:
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  version: '0'
109
110
  requirements: []
110
111
  rubyforge_project:
111
- rubygems_version: 2.7.3
112
+ rubygems_version: 2.7.6
112
113
  signing_key:
113
114
  specification_version: 4
114
115
  summary: Simple wrapper of Honeybadger