getaround_utils 0.2.37 → 0.2.38

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: ef85783014358aa9de1a8e177a58dbf5f8df596583f8caeb73d5490638a91f8f
4
- data.tar.gz: f10368811d122f9a54a451e29abcdf527c3d6d86e1c634ded313860dc910c667
3
+ metadata.gz: 916e4ff4d5a7e304388761fa589ed6d5cf6607415323db868832e098176898da
4
+ data.tar.gz: 909e21f9dc77e1da802084938478197acf05f4020922873cfe4867d2bcc727e4
5
5
  SHA512:
6
- metadata.gz: 5ce5ae96d95d0d57a9dd3ba2203e3593d38c7dd37147641af60da821307ad0fb6f3e52c0982f72f593d8f574c36d9ec34705a3444c78432874b6c233065793ff
7
- data.tar.gz: b59465dbc69f32174b784d6e3c29e643b52a5376c642bfb291c0a304677007d802fb36c256925a238f5f29092a3fc397ce4923acfdada529029d20464c21b474
6
+ metadata.gz: 9172dc32867f096bebd47bcad9cefaf38a02085917d91af8254d942496ab159a1b9f12aa60692f8e0c84dd370e9f2633a85f3314589d8ef60abc751137a7da9e
7
+ data.tar.gz: a0c67681e628904bf1b36b4f1fe726bd8a33951b595e301d5da55de4a187d02714721d2952775688f4cf94082fa2118b2ac49302b0f63985debfb04fa3a54f53
data/CHANGELOG.md ADDED
@@ -0,0 +1,35 @@
1
+ ## [0.2.38] 2025-11-19
2
+
3
+ ### Added
4
+
5
+ - `GetaroundUtils::Utils::HandleError` ([#433](https://github.com/drivy/backend-configs/pull/433))
6
+ ```ruby
7
+ module MyApp::Errors
8
+ def self.handle(error, **)
9
+ GetaroundUtils::Utils::HandleError.notify_of(error, **) do |report|
10
+ report.grouping_hash = 'hello-world' # Bugsnag example
11
+ end
12
+ end
13
+ end
14
+ ```
15
+ - `GetaroundUtils::Utils::ConfigUrl` ([#432](https://github.com/drivy/backend-configs/pull/432))
16
+ ```ruby
17
+ # FOO_URL="redis://foo@localhost:666/10"
18
+ # FOO_PASSWORD="added-pwd"
19
+ # BAR_URL="whatever://bar:used-pwd@localhost:666/42"
20
+ # BAR_PASSWORD="not-used-pwd"
21
+ # ENV_TEST_NUMBER=1
22
+
23
+ GetaroundUtils::Utils::ConfigUrl
24
+ .from_env('FOO')
25
+ .tap { |uri| uri.path += ENV['ENV_TEST_NUMBER'] }
26
+ # => <URI::Generic redis://foo:added-pwd@localhost:666/101>
27
+ GetaroundUtils::Utils::ConfigUrl.from_env('BAR').to_s
28
+ # => "whatever://bar:used-pwd@localhost:666/42"
29
+ GetaroundUtils::Utils::ConfigUrl.from_env('UNKNOWN')
30
+ # => KeyError: key not found "UNKNOWN_URL"
31
+ GetaroundUtils::Utils::ConfigUrl.from_env('UNKNOWN', 'mysql://localhost/test')
32
+ # => <URI::Generic mysql://localhost/test>
33
+ GetaroundUtils::Utils::ConfigUrl.from_env('UNKNOWN') { GetaroundUtils::Utils::ConfigUrl.from_env('BAZ') }
34
+ # => KeyError: key not found "BAZ_URL"
35
+ ```
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- getaround_utils (0.2.37)
4
+ getaround_utils (0.2.38)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -49,6 +49,44 @@ require 'getaround_utils/railties/ougai'
49
49
 
50
50
  For more details, [read the spec](spec/getaround_utils/railties/ougai_spec.rb)
51
51
 
52
+ ## Engines
53
+
54
+ ### GetaroundUtils::Engine::Health
55
+
56
+ - Exposes the currently deployed release version:
57
+ - `GetaroundUtils::Engine::Health.release_version`
58
+ - Exposes the currently deployed commit SHA1:
59
+ - `GetaroundUtils::Engine::Health.commit_sha1`
60
+ - Provides a `Rack` application to expose "health" endpoints (used by Shipit)
61
+ - `GET /release_version`
62
+ - `GET /commit_sha1`
63
+ - `GET /migration_status`
64
+
65
+ The engine can be mounted in a Rails application:
66
+ ```ruby
67
+ # config/routes.rb
68
+ require 'getaround_utils/engines/health'
69
+
70
+ Rails.application.routes.draw do
71
+ mount GetaroundUtils::Engines::Health.engine, at: '/health'
72
+ # ...
73
+ end
74
+ ```
75
+
76
+ Or in a simple `Rack` application:
77
+ ```ruby
78
+ # config.ru
79
+ require 'getaround_utils/engines/health'
80
+
81
+ run Rack::Builder.new {
82
+ map '/health' do
83
+ run GetaroundUtils::Engines::Health.engine
84
+ end
85
+ # ...
86
+ }
87
+ ```
88
+ *This will generates `/health/release_version`, `/health/commit_sha1` and `/health/migration_status` endpoints*
89
+
52
90
  ## Mixins
53
91
 
54
92
  ### GetaroundUtils::Mixins::Loggable
@@ -100,11 +138,62 @@ For more details, [read the spec](spec/getaround_utils/mixins/loggable_spec.rb#L
100
138
 
101
139
  ## Misc
102
140
 
103
- ### GetaroundUtils::LogFormatters::DeepKeyValue
141
+ ### GetaroundUtils::Utils::DeepKeyValue
104
142
 
105
143
  This log formatter will serialize an object of any depth into a key-value string.
106
144
  It supports basic scalars (ie: `Hash`,`Array`,`Numeric`,`String`) and will call "#inspect" for any other type.
107
145
 
108
- For more details, [read the spec](spec/getaround_utils/log_formatters/deep_key_value_spec.rb)
146
+ For more details, [read the spec](spec/getaround_utils/utils/deep_key_value_spec.rb)
147
+
148
+ ### GetaroundUtils::Utils::ConfigUrl
149
+
150
+ This helper allows to manage configuration urls with password extracted in a dedicated variable.
109
151
 
152
+ It uses `*_URL` variable and tries to compute `*_PASSWORD` inside the parsed url.
153
+
154
+ ```ruby
155
+ # FOO_URL="redis://foo@localhost:666/10"
156
+ # FOO_PASSWORD="added-pwd"
157
+ # BAR_URL="whatever://bar:used-pwd@localhost:666/42"
158
+ # BAR_PASSWORD="not-used-pwd"
159
+ # ENV_TEST_NUMBER=1
160
+
161
+ GetaroundUtils::Utils::ConfigUrl
162
+ .from_env('FOO')
163
+ .tap { |uri| uri.path += ENV['ENV_TEST_NUMBER'] }
164
+ # => <URI::Generic redis://foo:added-pwd@localhost:666/101>
165
+ GetaroundUtils::Utils::ConfigUrl.from_env('BAR').to_s
166
+ # => "whatever://bar:used-pwd@localhost:666/42"
167
+ GetaroundUtils::Utils::ConfigUrl.from_env('UNKNOWN')
168
+ # => KeyError: key not found "UNKNOWN_URL"
169
+ GetaroundUtils::Utils::ConfigUrl.from_env('UNKNOWN', 'mysql://localhost/test')
170
+ # => <URI::Generic mysql://localhost/test>
171
+ GetaroundUtils::Utils::ConfigUrl.from_env('UNKNOWN') { GetaroundUtils::Utils::ConfigUrl.from_env('BAZ') }
172
+ # => KeyError: key not found "BAZ_URL"
173
+ ```
174
+
175
+ For more details, [read the spec](spec/getaround_utils/utils/config_url_spec.rb)
176
+
177
+ ### GetaroundUtils::Utils::HandleError
178
+
179
+ Allows to easily notify our error provider by providing context metadata as keyword arguments.
180
+
181
+ *If there is no error provider defined, a `debug` message will be logged using `GetaroundUtils::Mixins::Loggable`*
182
+
183
+ ```ruby
184
+ module MyApp::Errors
185
+ def self.handle(error, **)
186
+ GetaroundUtils::Utils::HandleError.notify_of(error, **) do |event|
187
+ event.grouping_hash = 'hello-world' # Bugsnag example
188
+ end
189
+ end
190
+ end
191
+
192
+ begin
193
+ raise 'woopsie'
194
+ rescue StandardError => e
195
+ MyApp::Errors.handle(e, foo: 'bar', baz: 42)
196
+ end
197
+ ```
110
198
 
199
+ For more details, [read the spec](spec/getaround_utils/utils/handle_error_spec.rb)
@@ -17,6 +17,10 @@ Gem::Specification.new do |gem|
17
17
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
18
18
  end
19
19
 
20
+ gem.metadata = {
21
+ "changelog_uri" => "https://github.com/drivy/backend-configs/blob/main/getaround_utils/CHANGELOG.md",
22
+ }
23
+
20
24
  # Development dependencies
21
25
  gem.add_development_dependency 'getaround-rubocop', '= 0.2.11'
22
26
  gem.add_development_dependency 'irb', '~> 1.15'
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+
5
+ module GetaroundUtils; end
6
+
7
+ module GetaroundUtils::Utils; end
8
+
9
+ module GetaroundUtils::Utils::ConfigUrl
10
+ def self.from_env(config_name, ...)
11
+ env_url = ENV.fetch("#{config_name}_URL", ...)
12
+ env_pwd = ENV.fetch("#{config_name}_PASSWORD", nil)
13
+ return if env_url.nil?
14
+
15
+ ::URI.parse(env_url).tap do |uri|
16
+ if env_pwd && !uri.userinfo
17
+ uri.userinfo = ":#{env_pwd}"
18
+ elsif env_pwd
19
+ uri.password ||= env_pwd
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'getaround_utils/mixins/loggable'
4
+
5
+ module GetaroundUtils; end
6
+
7
+ module GetaroundUtils::Utils; end
8
+
9
+ module GetaroundUtils::Utils::HandleError
10
+ extend GetaroundUtils::Mixins::Loggable
11
+
12
+ # @see https://docs.bugsnag.com/platforms/ruby/rails/reporting-handled-errors/#sending-custom-diagnostics
13
+ def self.notify_of(error, **metadata, &)
14
+ if defined?(::Bugsnag)
15
+ ::Bugsnag.notify(error) do |event|
16
+ metadata.each do |name, value|
17
+ if value.is_a?(Hash)
18
+ event.add_metadata(name, value)
19
+ else
20
+ event.add_metadata('custom', name, value)
21
+ end
22
+ end
23
+ yield event if block_given?
24
+ end
25
+ else
26
+ loggable_log(
27
+ :debug,
28
+ 'handled_error',
29
+ error_class: error.class.name,
30
+ error_message: error.to_s,
31
+ **metadata
32
+ )
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'getaround_utils/utils/config_url'
3
4
  require 'getaround_utils/utils/deep_key_value'
5
+ require 'getaround_utils/utils/handle_error'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GetaroundUtils
4
- VERSION = '0.2.37'
4
+ VERSION = '0.2.38'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getaround_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.37
4
+ version: 0.2.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drivy
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-08-26 00:00:00.000000000 Z
12
+ date: 2025-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: getaround-rubocop
@@ -202,6 +202,7 @@ extra_rdoc_files: []
202
202
  files:
203
203
  - ".rubocop.yml"
204
204
  - ".ruby-version"
205
+ - CHANGELOG.md
205
206
  - Gemfile
206
207
  - Gemfile.lock
207
208
  - README.md
@@ -218,12 +219,15 @@ files:
218
219
  - lib/getaround_utils/railties/lograge.rb
219
220
  - lib/getaround_utils/railties/ougai.rb
220
221
  - lib/getaround_utils/utils.rb
222
+ - lib/getaround_utils/utils/config_url.rb
221
223
  - lib/getaround_utils/utils/deep_key_value.rb
224
+ - lib/getaround_utils/utils/handle_error.rb
222
225
  - lib/getaround_utils/version.rb
223
226
  homepage: https://github.com/drivy
224
227
  licenses:
225
228
  - MIT
226
- metadata: {}
229
+ metadata:
230
+ changelog_uri: https://github.com/drivy/backend-configs/blob/main/getaround_utils/CHANGELOG.md
227
231
  post_install_message:
228
232
  rdoc_options: []
229
233
  require_paths:
@@ -239,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
243
  - !ruby/object:Gem::Version
240
244
  version: '0'
241
245
  requirements: []
242
- rubygems_version: 3.5.16
246
+ rubygems_version: 3.5.21
243
247
  signing_key:
244
248
  specification_version: 4
245
249
  summary: Backend shared utility classes