dry-behaviour 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eca195e7f40df7dbd0ff8719938bbca1c717c82c
4
- data.tar.gz: 820195b2a867f6e5c1a350b991108259b47c5888
3
+ metadata.gz: e6de5e26b1d3d57039660055f9248c1a3df5431d
4
+ data.tar.gz: 17404270b966673dd7d7c56d6966d1a93cf58cfd
5
5
  SHA512:
6
- metadata.gz: f106a7ad2a2a4548d17aeeb0053cd8875ce8126330b5cd3ae4d51219e73b564a2a6fe29ab9841e31ac3e506e1746013a96dde1d40ed094ecf18fe09e5fa7e4e4
7
- data.tar.gz: bb91d87c3442fd30ea5887a33ca604000d1789f9a60907d0a9b3d2f29ab37966a3ff8b9574a22414307c22309d1ea2d2b0e15f4eb8ec606717d2b24ca1dc496c
6
+ metadata.gz: bb1ddcc3af289266d79dfd8c38b33fd47f4db8f3d2533e4aec395ff353490876bbf2554e241b23c5e56b45b81bec623f79baa97eede969071ab07c7ab7e24eba
7
+ data.tar.gz: 02e81fe058128b1ebdbb4fe34ed5811c9bd6da01ab91742235bb57f87b29adfc3824d33885e507137e724fffac7d793d3a33da7882b4dc766de8601a7df43c0e
@@ -3,18 +3,22 @@ name: Ruby
3
3
  on: [push]
4
4
 
5
5
  jobs:
6
- build:
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
- - uses: actions/checkout@v1
12
- - name: Set up Ruby 2.3.8
13
- uses: ruby/setup-ruby@v1
14
- with:
15
- ruby-version: 2.3.8
16
- - name: Build and test with Rake
17
- run: |
18
- gem install bundler
19
- bundle install --jobs 4 --retry 3
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[dry-behaviour/lib/dry/behaviour]
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 ? @logger : Class.new { def warn(*); end }.new
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.new(self) if BlackTie.protocols.key?(self)
37
- raise ::Dry::Protocol::MalformedDefinition.new(self) unless block_given?
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
- raise Dry::Protocol::NotImplemented.new(
62
- :protocol, inspect,
63
- method: method, receiver: receiver, args: args, self: self
64
- ) unless impl
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
- :nested, inspect,
76
- cause: e,
77
- method: method, receiver: receiver, args: args, impl: impl, self: self
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 % [Dry::BlackTie.proto_caller, self.inspect, name])
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 % [Dry::BlackTie.proto_caller, type, self.inspect, name])
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 % [Dry::BlackTie.proto_caller, protocol.inspect, m, target]
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], [:rest]].include?(params.map(&:first))) ||
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
- BlackTie.Logger.warn(
148
- WRONG_PARAMETER_DECLARATION % [Dry::BlackTie.proto_caller, protocol.inspect, m, target, BlackTie.protocols[protocol][m].map(&:first)]
149
- ) unless ok
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
- "  ⮩ in call to %s#defmethod(%s).".freeze
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
- "  ⮩ Expected: %s".freeze
218
+ '  ⮩ Expected: %s'.freeze
205
219
 
206
220
  private
207
221
 
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Behaviour
3
- VERSION = '0.12.0'.freeze
3
+ VERSION = '0.12.1'.freeze
4
4
  end
5
5
  end
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.0
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: 2022-12-07 00:00:00.000000000 Z
13
+ date: 2023-02-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler