dry-behaviour 0.12.0 → 0.12.1
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/.github/workflows/ci.yml +15 -11
- data/lib/dry/behaviour/black_tie.rb +37 -23
- data/lib/dry/behaviour/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6de5e26b1d3d57039660055f9248c1a3df5431d
|
4
|
+
data.tar.gz: 17404270b966673dd7d7c56d6966d1a93cf58cfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb1ddcc3af289266d79dfd8c38b33fd47f4db8f3d2533e4aec395ff353490876bbf2554e241b23c5e56b45b81bec623f79baa97eede969071ab07c7ab7e24eba
|
7
|
+
data.tar.gz: 02e81fe058128b1ebdbb4fe34ed5811c9bd6da01ab91742235bb57f87b29adfc3824d33885e507137e724fffac7d793d3a33da7882b4dc766de8601a7df43c0e
|
data/.github/workflows/ci.yml
CHANGED
@@ -3,18 +3,22 @@ name: Ruby
|
|
3
3
|
on: [push]
|
4
4
|
|
5
5
|
jobs:
|
6
|
-
|
6
|
+
test:
|
7
7
|
|
8
8
|
runs-on: ubuntu-latest
|
9
9
|
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
matrix:
|
13
|
+
ruby-version: ['head', '3.1', '3.0', '2.7']
|
14
|
+
|
10
15
|
steps:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
bundle
|
20
|
-
bundle exec rspec
|
16
|
+
- uses: actions/checkout@v3
|
17
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
18
|
+
uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108
|
19
|
+
with:
|
20
|
+
ruby-version: ${{ matrix.ruby-version }}
|
21
|
+
- name: Install dependencies
|
22
|
+
run: bundle install --jobs 4 --retry 3
|
23
|
+
- name: Run tests
|
24
|
+
run: bundle exec rspec
|
@@ -8,7 +8,7 @@ module Dry
|
|
8
8
|
class << self
|
9
9
|
def proto_caller
|
10
10
|
caller.drop_while do |line|
|
11
|
-
line =~ %r
|
11
|
+
line =~ %r{dry-behaviour/lib/dry/behaviour}
|
12
12
|
end.first
|
13
13
|
end
|
14
14
|
|
@@ -20,7 +20,7 @@ module Dry
|
|
20
20
|
require 'logger'
|
21
21
|
Logger.new($stdout)
|
22
22
|
end
|
23
|
-
@logger
|
23
|
+
@logger || Class.new { def warn(*); end }.new
|
24
24
|
end
|
25
25
|
|
26
26
|
def protocols
|
@@ -33,8 +33,8 @@ module Dry
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def defprotocol(implicit_inheritance: false, &λ)
|
36
|
-
raise ::Dry::Protocol::DuplicateDefinition
|
37
|
-
raise ::Dry::Protocol::MalformedDefinition
|
36
|
+
raise ::Dry::Protocol::DuplicateDefinition, self if BlackTie.protocols.key?(self)
|
37
|
+
raise ::Dry::Protocol::MalformedDefinition, self unless block_given?
|
38
38
|
|
39
39
|
BlackTie.protocols[self][:__implicit_inheritance__] = !!implicit_inheritance
|
40
40
|
|
@@ -55,13 +55,23 @@ module Dry
|
|
55
55
|
end
|
56
56
|
|
57
57
|
BlackTie.protocols[self].each do |method, *_m_args, **_m_kwargs| # FIXME: CHECK ARITY HERE
|
58
|
-
singleton_class.send :define_method, method do |receiver, *args, **kwargs|
|
58
|
+
# singleton_class.send :define_method, method do |receiver, *args, **kwargs|
|
59
|
+
singleton_class.send :define_method, method do |*args, **kwargs|
|
60
|
+
if args == []
|
61
|
+
receiver = kwargs
|
62
|
+
kwargs = {}
|
63
|
+
else
|
64
|
+
receiver, *args = args
|
65
|
+
end
|
66
|
+
|
59
67
|
impl = implementation_for(receiver)
|
60
68
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
69
|
+
unless impl
|
70
|
+
raise Dry::Protocol::NotImplemented.new(
|
71
|
+
:protocol, inspect,
|
72
|
+
method: method, receiver: receiver, args: args, self: self
|
73
|
+
)
|
74
|
+
end
|
65
75
|
|
66
76
|
begin
|
67
77
|
# [AM] [v1] [FIXME] for modern rubies `if` is redundant
|
@@ -70,12 +80,12 @@ module Dry
|
|
70
80
|
else
|
71
81
|
impl[method].(*args.unshift(receiver), **kwargs)
|
72
82
|
end
|
73
|
-
rescue => e
|
83
|
+
rescue StandardError => e
|
74
84
|
raise Dry::Protocol::NotImplemented.new(
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
85
|
+
:nested, inspect,
|
86
|
+
cause: e,
|
87
|
+
method: method, receiver: receiver, args: args, impl: impl, self: self
|
88
|
+
)
|
79
89
|
end
|
80
90
|
end
|
81
91
|
end
|
@@ -87,13 +97,13 @@ module Dry
|
|
87
97
|
|
88
98
|
def defmethod(name, *params)
|
89
99
|
if params.size.zero? || params.first.is_a?(Array) && params.first.last != :req
|
90
|
-
BlackTie.Logger.warn(IMPLICIT_RECEIVER_DECLARATION
|
100
|
+
BlackTie.Logger.warn(format(IMPLICIT_RECEIVER_DECLARATION, Dry::BlackTie.proto_caller, inspect, name))
|
91
101
|
params.unshift(:this)
|
92
102
|
end
|
93
103
|
params =
|
94
104
|
params.map do |p, type|
|
95
105
|
if type && !PARAM_TYPES.include?(type)
|
96
|
-
BlackTie.Logger.warn(UNKNOWN_TYPE_DECLARATION
|
106
|
+
BlackTie.Logger.warn(format(UNKNOWN_TYPE_DECLARATION, Dry::BlackTie.proto_caller, type, inspect, name))
|
97
107
|
type = nil
|
98
108
|
end
|
99
109
|
[type || (PARAM_TYPES.include?(p) ? p : :req), p]
|
@@ -127,7 +137,7 @@ module Dry
|
|
127
137
|
end
|
128
138
|
else
|
129
139
|
BlackTie.Logger.warn(
|
130
|
-
IMPLICIT_DELEGATE_DEPRECATION
|
140
|
+
format(IMPLICIT_DELEGATE_DEPRECATION, Dry::BlackTie.proto_caller, protocol.inspect, m, target)
|
131
141
|
)
|
132
142
|
DELEGATE_METHOD.(mod.singleton_class, [m] * 2)
|
133
143
|
end
|
@@ -140,13 +150,17 @@ module Dry
|
|
140
150
|
proto = BlackTie.protocols[protocol]
|
141
151
|
ok =
|
142
152
|
mds.map(&:first).include?(m) ||
|
143
|
-
((proto[m] == {} || proto[:__implicit_inheritance__]) && [[:req],
|
153
|
+
((proto[m] == {} || proto[:__implicit_inheritance__]) && [[:req],
|
154
|
+
[:rest]].include?(params.map(&:first))) ||
|
144
155
|
[proto[m], params].map { |args| args.map(&:first) }.reduce(:==)
|
145
156
|
|
146
157
|
# TODO[1.0] raise NotImplemented(:arity)
|
147
|
-
|
148
|
-
|
149
|
-
|
158
|
+
unless ok
|
159
|
+
BlackTie.Logger.warn(
|
160
|
+
format(WRONG_PARAMETER_DECLARATION, Dry::BlackTie.proto_caller, protocol.inspect, m, target,
|
161
|
+
BlackTie.protocols[protocol][m].map(&:first))
|
162
|
+
)
|
163
|
+
end
|
150
164
|
|
151
165
|
BlackTie.implementations[protocol][tgt][m] = mod.method(m).to_proc
|
152
166
|
end
|
@@ -188,7 +202,7 @@ module Dry
|
|
188
202
|
"\n⚠️ TOO IMPLICIT → %s\n" \
|
189
203
|
" ⮩ Implicit declaration of `this' parameter in `defmethod'.\n" \
|
190
204
|
" ⮩ Whilst it’s allowed, we strongly encourage to explicitly declare it\n" \
|
191
|
-
|
205
|
+
' ⮩ in call to %s#defmethod(%s).'.freeze
|
192
206
|
|
193
207
|
UNKNOWN_TYPE_DECLARATION =
|
194
208
|
"\n⚠️ UNKNOWN TYPE → %s\n" \
|
@@ -201,7 +215,7 @@ module Dry
|
|
201
215
|
" ⮩ Wrong parameters declaration will be removed in 1.0\n" \
|
202
216
|
" ⮩ %s#%s was implemented for %s with unexpected parameters.\n" \
|
203
217
|
" ⮩ Consider implementing interfaces exactly as they were declared.\n" \
|
204
|
-
|
218
|
+
' ⮩ Expected: %s'.freeze
|
205
219
|
|
206
220
|
private
|
207
221
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-behaviour
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksei Matiushkin
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-02-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|