dry-behaviour 0.11.2 → 0.12.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
- SHA256:
3
- metadata.gz: 232921c25386484f9538bbe49039c133c1de8e2d2cd85b9545a4de3736344385
4
- data.tar.gz: 38625102473e08efc17d5162db60e1fc9a90633f81695ecb60f26f395237f976
2
+ SHA1:
3
+ metadata.gz: eca195e7f40df7dbd0ff8719938bbca1c717c82c
4
+ data.tar.gz: 820195b2a867f6e5c1a350b991108259b47c5888
5
5
  SHA512:
6
- metadata.gz: 4c4c5d71d32fcfe4bef6fb13e21ddcd8a32afc63cdbf3bda1dc97428d56332f99e02fd15cb15db9b3ecafb719812e6889587794598dd666335d02e67780b6ae9
7
- data.tar.gz: 3d556f70828ded92ad615fd01ab27b1d7b4c70843bf2d16fa10de1a9102da08ea6f3284883aa2c37a2b0c830776c36ea5ed989cb50ef711e29c5dbb2cfa53531
6
+ metadata.gz: f106a7ad2a2a4548d17aeeb0053cd8875ce8126330b5cd3ae4d51219e73b564a2a6fe29ab9841e31ac3e506e1746013a96dde1d40ed094ecf18fe09e5fa7e4e4
7
+ data.tar.gz: bb91d87c3442fd30ea5887a33ca604000d1789f9a60907d0a9b3d2f29ab37966a3ff8b9574a22414307c22309d1ea2d2b0e15f4eb8ec606717d2b24ca1dc496c
@@ -9,12 +9,12 @@ jobs:
9
9
 
10
10
  steps:
11
11
  - uses: actions/checkout@v1
12
- - name: Set up Ruby 2.6
13
- uses: actions/setup-ruby@v1
12
+ - name: Set up Ruby 2.3.8
13
+ uses: ruby/setup-ruby@v1
14
14
  with:
15
- ruby-version: 2.6.x
15
+ ruby-version: 2.3.8
16
16
  - name: Build and test with Rake
17
17
  run: |
18
18
  gem install bundler
19
19
  bundle install --jobs 4 --retry 3
20
- bundle exec rake
20
+ bundle exec rspec
@@ -15,10 +15,10 @@ jobs:
15
15
 
16
16
  steps:
17
17
  - uses: actions/checkout@master
18
- - name: Set up Ruby 2.6
19
- uses: actions/setup-ruby@v1
18
+ - name: Set up Ruby 2.3.8
19
+ uses: ruby/setup-ruby@v1
20
20
  with:
21
- version: 2.6.x
21
+ version: 2.3.8
22
22
 
23
23
  - name: Publish to GPR
24
24
  run: |
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.3.8
data/README.md CHANGED
@@ -60,6 +60,45 @@ expect(Protocols::Adder.add(nil, 10)).to eq(10)
60
60
  expect(Protocols::Adder.add_default(1)).to eq(6)
61
61
  ```
62
62
 
63
+ ### Arguments types
64
+
65
+ Normally, one would use a simple notation to declare a method. It includes `:this` receiver
66
+ in te very first position and some optional required arguments afterward.
67
+
68
+ ```ruby
69
+ defmethod :add, :this, :addend
70
+ ...
71
+ defimpl ... do
72
+ def add(this, addend); this + addend; end
73
+ end
74
+ ```
75
+
76
+ If the argument is not generic (optional, or splatted, or keyword,) its type must be explicitly
77
+ specified in the protocol definition as shown below.
78
+
79
+ ```ruby
80
+ defprotocol implicit_inheritance: true do
81
+ defmethod :with_def_argument, :this, [:foo_opt, :opt]
82
+ defmethod :with_def_keyword_argument, :this, [:foo_key, :key]
83
+ defmethod :with_req_keyword_argument, :this, [:foo_key, :keyreq]
84
+
85
+ def with_def_argument(this, foo_opt = :super); foo_opt; end
86
+ def with_def_keyword_argument(this, foo_key: :super); foo_key; end
87
+ def with_req_keyword_argument(this, foo_key:); foo_key; end
88
+ ...
89
+ ```
90
+
91
+ That said, `:addend` argument declaration is a syntactic sugar for `[:addend, :req]`.
92
+ Possible values for the type are:
93
+
94
+ ```ruby
95
+ PARAM_TYPES = %i[req opt rest key keyrest keyreq block]
96
+ ```
97
+
98
+ Please note, that the signature of the method and its implementation must exactly match.
99
+ One cannot declare a method to have a `keyreq` argument and then make it defaulted in the
100
+ implementation. That is done by design.
101
+
63
102
  ## Guards
64
103
 
65
104
  Starting with `v0.5.0` we support multiple function clauses and guards.
@@ -54,15 +54,22 @@ module Dry
54
54
  end.reject(&:nil?).first
55
55
  end
56
56
 
57
- BlackTie.protocols[self].each do |method, *_| # FIXME: CHECK ARITY HERE
58
- singleton_class.send :define_method, method do |receiver = nil, *args|
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|
59
59
  impl = implementation_for(receiver)
60
+
60
61
  raise Dry::Protocol::NotImplemented.new(
61
62
  :protocol, inspect,
62
63
  method: method, receiver: receiver, args: args, self: self
63
64
  ) unless impl
65
+
64
66
  begin
65
- impl[method].(*args.unshift(receiver))
67
+ # [AM] [v1] [FIXME] for modern rubies `if` is redundant
68
+ if kwargs.empty?
69
+ impl[method].(*args.unshift(receiver))
70
+ else
71
+ impl[method].(*args.unshift(receiver), **kwargs)
72
+ end
66
73
  rescue => e
67
74
  raise Dry::Protocol::NotImplemented.new(
68
75
  :nested, inspect,
@@ -89,7 +96,7 @@ module Dry
89
96
  BlackTie.Logger.warn(UNKNOWN_TYPE_DECLARATION % [Dry::BlackTie.proto_caller, type, self.inspect, name])
90
97
  type = nil
91
98
  end
92
- [type || PARAM_TYPES.include?(p) ? p : :req, p]
99
+ [type || (PARAM_TYPES.include?(p) ? p : :req), p]
93
100
  end
94
101
  BlackTie.protocols[self][name] = params
95
102
  end
@@ -109,8 +116,13 @@ module Dry
109
116
  (NORMALIZE_KEYS.(protocol) - meths).each_with_object(meths) do |m, acc|
110
117
  if BlackTie.protocols[protocol][:__implicit_inheritance__]
111
118
  mod.singleton_class.class_eval do
112
- define_method m do |this, *♿_args, &♿_λ|
113
- super(this, *♿_args, &♿_λ)
119
+ define_method m do |this, *♿_args, **♿_kwargs, &♿_λ|
120
+ # [AM] [v1] [FIXME] for modern rubies `if` is redundant
121
+ if ♿_kwargs.empty?
122
+ super(this, *♿_args, &♿_λ)
123
+ else
124
+ super(this, *♿_args, **♿_kwargs, &♿_λ)
125
+ end
114
126
  end
115
127
  end
116
128
  else
@@ -143,7 +155,7 @@ module Dry
143
155
  end
144
156
  module_function :defimpl
145
157
 
146
- PARAM_TYPES = %i[req opt rest keyrest block]
158
+ PARAM_TYPES = %i[req opt rest key keyrest keyreq block]
147
159
 
148
160
  DELEGATE_METHOD = lambda do |klazz, (source, target)|
149
161
  klazz.class_eval do
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Behaviour
3
- VERSION = '0.11.2'.freeze
3
+ VERSION = '0.12.0'.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.11.2
4
+ version: 0.12.0
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-07-08 00:00:00.000000000 Z
13
+ date: 2022-12-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -111,7 +111,7 @@ files:
111
111
  - ".rspec"
112
112
  - ".rubocop.yml"
113
113
  - ".rubocop_todo.yml"
114
- - ".travis.yml"
114
+ - ".tool-versions"
115
115
  - CODE_OF_CONDUCT.md
116
116
  - Gemfile
117
117
  - LICENSE.txt
@@ -149,7 +149,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  - !ruby/object:Gem::Version
150
150
  version: '0'
151
151
  requirements: []
152
- rubygems_version: 3.3.3
152
+ rubyforge_project:
153
+ rubygems_version: 2.5.2.3
153
154
  signing_key:
154
155
  specification_version: 4
155
156
  summary: Tiny library inspired by Elixir protocol pattern.
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.1.1
4
- - 2.1.10
5
- - 2.2.2
6
- - 2.5.1
7
- before_install: gem install bundler -v 1.14.6