hanami-utils 3.0.0 → 3.1.0.rc1
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 +4 -4
- data/CHANGELOG.md +22 -1
- data/README.md +1 -1
- data/hanami-utils.gemspec +1 -1
- data/lib/hanami/utils/callbacks.rb +52 -4
- data/lib/hanami/utils/deprecation.rb +10 -11
- data/lib/hanami/utils/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 657a294bd7584897a29fe3f2d893f8edc38d9f8d864a58ebe2ad6d97d4ad991a
|
|
4
|
+
data.tar.gz: e1ce607909b6b2232d318be0472bbf138579c8216b7d62efa83baf71c23cda99
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5f136f5b12c05372a795bbf4cf3a78d58562195ea16fe3d33f1a9c6af0cace4639e39c774fd1a202d144fb1c5b92d499c62e7b3ec812f56f808e4c62571bd091
|
|
7
|
+
data.tar.gz: 973aabde17cef7e5db1b2466d2f46102ee795f385fbde9a03f4fe08f100c491bb39836c37aac59f211cbb7c5efad05b22bc56199192a3a41bc21413dde04956a
|
data/CHANGELOG.md
CHANGED
|
@@ -19,7 +19,28 @@ and this project adheres to [Break Versioning](https://www.taoensso.com/break-ve
|
|
|
19
19
|
|
|
20
20
|
### Security
|
|
21
21
|
|
|
22
|
-
[Unreleased]: https://github.com/hanami/hanami-utils/compare/v3.0.
|
|
22
|
+
[Unreleased]: https://github.com/hanami/hanami-utils/compare/v3.1.0.rc1...main
|
|
23
|
+
|
|
24
|
+
## [3.1.0.rc1] - 2026-11-27
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- To be consistent, lambdas and callables in callbacks no longer enforce function arity (just like procs/blocks). (@ziggythehamster in #421)
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- Callbacks now support non-proc callables as intended. (@ziggythehamster in #421, @timriley in #424)
|
|
33
|
+
- `Hanami::Utils::Deprecation` reports the correct calling location on all Ruby engines and versions, including the latest JRuby. (@timriley in #423)
|
|
34
|
+
|
|
35
|
+
[3.1.0.rc1]: https://github.com/hanami/hanami-utils/compare/v3.0.1...v3.1.0.rc1
|
|
36
|
+
|
|
37
|
+
## [3.0.1] - 2026-07-03
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- Allow BigDecimal versions 3 or 4. (@sandbergja in #419)
|
|
42
|
+
|
|
43
|
+
[3.0.1]: https://github.com/hanami/hanami-utils/compare/v3.0.0...v3.0.1
|
|
23
44
|
|
|
24
45
|
## [3.0.0] - 2026-06-30
|
|
25
46
|
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[actions]: https://github.com/hanami/hanami-utils/actions
|
|
4
4
|
[chat]: https://discord.gg/naQApPAsZB
|
|
5
|
-
[forum]: https://discourse.
|
|
5
|
+
[forum]: https://discourse.hanakai.org
|
|
6
6
|
[rubygem]: https://rubygems.org/gems/hanami-utils
|
|
7
7
|
|
|
8
8
|
# Hanami Utils [][rubygem] [][actions]
|
data/hanami-utils.gemspec
CHANGED
|
@@ -33,6 +33,6 @@ Gem::Specification.new do |spec|
|
|
|
33
33
|
spec.add_runtime_dependency "dry-core", "~> 1.0", "< 2"
|
|
34
34
|
spec.add_runtime_dependency "dry-transformer", "~> 1.0", "< 2"
|
|
35
35
|
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
|
36
|
-
spec.add_runtime_dependency "bigdecimal", "
|
|
36
|
+
spec.add_runtime_dependency "bigdecimal", ">= 3.1"
|
|
37
37
|
end
|
|
38
38
|
|
|
@@ -53,6 +53,15 @@ module Hanami
|
|
|
53
53
|
# chain.append { Authenticator.authenticate! }
|
|
54
54
|
# chain.append { |params| ArticleRepository.new.find(params[:id]) }
|
|
55
55
|
#
|
|
56
|
+
# # Add a callable that isn't a proc, and it will be wrapped by `Callback` as well.
|
|
57
|
+
# module LivenessProbeCallback
|
|
58
|
+
# extend self
|
|
59
|
+
#
|
|
60
|
+
# def call = LivenessProbe.alive!
|
|
61
|
+
# end
|
|
62
|
+
#
|
|
63
|
+
# chain.append LivenessProbeCallback
|
|
64
|
+
#
|
|
56
65
|
# # Append a Symbol as a reference to a method name that will be used as a callback.
|
|
57
66
|
# # It will wrapped by `MethodCallback`
|
|
58
67
|
# # If the #notificate method accepts some argument(s) they should be passed when `run` is invoked.
|
|
@@ -92,6 +101,15 @@ module Hanami
|
|
|
92
101
|
# chain.prepend { Authenticator.authenticate! }
|
|
93
102
|
# chain.prepend { |params| ArticleRepository.new.find(params[:id]) }
|
|
94
103
|
#
|
|
104
|
+
# # Add a callable that isn't a proc, and it will be wrapped by `Callback` as well.
|
|
105
|
+
# module LivenessProbeCallback
|
|
106
|
+
# extend self
|
|
107
|
+
#
|
|
108
|
+
# def call = LivenessProbe.alive!
|
|
109
|
+
# end
|
|
110
|
+
#
|
|
111
|
+
# chain.prepend LivenessProbeCallback
|
|
112
|
+
#
|
|
95
113
|
# # Add a Symbol as a reference to a method name that will be used as a callback.
|
|
96
114
|
# # It will wrapped by `MethodCallback`
|
|
97
115
|
# # If the #notificate method accepts some argument(s) they should be passed when `run` is invoked.
|
|
@@ -146,6 +164,8 @@ module Hanami
|
|
|
146
164
|
# # some other logic that requires `params`
|
|
147
165
|
# end
|
|
148
166
|
#
|
|
167
|
+
# chain.append SomeEncapsulatedLogic.new # if `call` takes arguments, it will get passed params
|
|
168
|
+
#
|
|
149
169
|
# chain.run(action, params)
|
|
150
170
|
#
|
|
151
171
|
# Those callbacks will be invoked within the context of `action`.
|
|
@@ -215,8 +235,8 @@ module Hanami
|
|
|
215
235
|
# @example
|
|
216
236
|
# require 'hanami/utils/callbacks'
|
|
217
237
|
#
|
|
218
|
-
# callable = Proc.new{} # it responds to #call
|
|
219
|
-
# method = :upcase
|
|
238
|
+
# callable = Proc.new {} # it responds to #call
|
|
239
|
+
# method = :upcase # it doesn't respond to #call
|
|
220
240
|
#
|
|
221
241
|
# Hanami::Utils::Callbacks::Factory.fabricate(callable).class
|
|
222
242
|
# # => Hanami::Utils::Callbacks::Callback
|
|
@@ -232,7 +252,8 @@ module Hanami
|
|
|
232
252
|
end
|
|
233
253
|
end
|
|
234
254
|
|
|
235
|
-
# Proc callback
|
|
255
|
+
# Proc and other callable callback.
|
|
256
|
+
#
|
|
236
257
|
# It wraps an object that responds to #call
|
|
237
258
|
#
|
|
238
259
|
# @since 0.1.0
|
|
@@ -267,7 +288,34 @@ module Hanami
|
|
|
267
288
|
#
|
|
268
289
|
# @see Hanami::Utils::Callbacks::Chain#run
|
|
269
290
|
def call(context, *args)
|
|
270
|
-
|
|
291
|
+
callback_proc =
|
|
292
|
+
if callback.respond_to?(:to_proc)
|
|
293
|
+
# Procs and 100% compatibles
|
|
294
|
+
callback
|
|
295
|
+
else
|
|
296
|
+
# Anything else that is callable
|
|
297
|
+
# NB: we convert to a proc because it's basically free and
|
|
298
|
+
# simplifies the code below, see: https://github.com/ruby/ruby/blob/973c45fcb3eb56df4f13d6aa54499e6ccb02809a/proc.c#L4204
|
|
299
|
+
callback.method(:call).to_proc
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
# Procs don't enforce arity, but lambdas and methods converted to procs do
|
|
303
|
+
if callback_proc.lambda?
|
|
304
|
+
context.instance_exec(*accepted_args(callback_proc, args), &callback_proc)
|
|
305
|
+
else
|
|
306
|
+
context.instance_exec(*args, &callback_proc)
|
|
307
|
+
end
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
private
|
|
311
|
+
|
|
312
|
+
# Returns the args that the given lambda accepts: all of them if it takes a splat, otherwise
|
|
313
|
+
# as many as its required and optional positional params.
|
|
314
|
+
def accepted_args(callback_proc, args)
|
|
315
|
+
params = callback_proc.parameters
|
|
316
|
+
return args if params.any? { |type, _| type == :rest }
|
|
317
|
+
|
|
318
|
+
args.take(params.count { |type, _| type == :req || type == :opt })
|
|
271
319
|
end
|
|
272
320
|
end
|
|
273
321
|
|
|
@@ -60,18 +60,17 @@ module Hanami
|
|
|
60
60
|
# # => old_method is deprecated, please use new_method - called from: test.rb:20:in `start'.
|
|
61
61
|
# # => started
|
|
62
62
|
def initialize(message)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
1
|
|
72
|
-
else
|
|
73
|
-
2
|
|
63
|
+
# Some Rubies include a frame for our own `.new` call at the top of the stack and some do
|
|
64
|
+
# not. Skip it if it's present (detect it through the frame having the same path and line as
|
|
65
|
+
# the frame after it). After that, the first frame is the deprecated method, and the next is
|
|
66
|
+
# its caller.
|
|
67
|
+
locations = caller_locations
|
|
68
|
+
first, second = locations
|
|
69
|
+
if first.base_label == "new" && first.path == second.path && first.lineno == second.lineno
|
|
70
|
+
locations.shift
|
|
74
71
|
end
|
|
72
|
+
|
|
73
|
+
::Kernel.warn("#{message} - called from: #{locations[1]}.")
|
|
75
74
|
end
|
|
76
75
|
end
|
|
77
76
|
end
|
data/lib/hanami/utils/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hanami-utils
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.
|
|
4
|
+
version: 3.1.0.rc1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hanakai team
|
|
@@ -67,14 +67,14 @@ dependencies:
|
|
|
67
67
|
name: bigdecimal
|
|
68
68
|
requirement: !ruby/object:Gem::Requirement
|
|
69
69
|
requirements:
|
|
70
|
-
- - "
|
|
70
|
+
- - ">="
|
|
71
71
|
- !ruby/object:Gem::Version
|
|
72
72
|
version: '3.1'
|
|
73
73
|
type: :runtime
|
|
74
74
|
prerelease: false
|
|
75
75
|
version_requirements: !ruby/object:Gem::Requirement
|
|
76
76
|
requirements:
|
|
77
|
-
- - "
|
|
77
|
+
- - ">="
|
|
78
78
|
- !ruby/object:Gem::Version
|
|
79
79
|
version: '3.1'
|
|
80
80
|
description: Ruby core extentions and Hanami utilities
|