dry-behaviour 0.11.1 → 0.12.0

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: e1d7d5dd7d7c114719b6115ba84f5f87f48af2c9
4
- data.tar.gz: 1ac765378c852e5dc1ca62bdf85cb97edc243531
3
+ metadata.gz: eca195e7f40df7dbd0ff8719938bbca1c717c82c
4
+ data.tar.gz: 820195b2a867f6e5c1a350b991108259b47c5888
5
5
  SHA512:
6
- metadata.gz: 3ad61d9eb05c86fb8b78699f914e1fef407db682250fb45a5c5533724d1e8ee5472b743b969254f29310cb641c355474854b69c912b60459ac116c4214fde00d
7
- data.tar.gz: eeb6c9852daaf477a95ae691a78bbb2b401397f8e7359972d4eee267bd746577b21f7ab8a514e9668d575587aecd4cecb78077b1ed14d52339454ad6e92faf93
6
+ metadata.gz: f106a7ad2a2a4548d17aeeb0053cd8875ce8126330b5cd3ae4d51219e73b564a2a6fe29ab9841e31ac3e506e1746013a96dde1d40ed094ecf18fe09e5fa7e4e4
7
+ data.tar.gz: bb91d87c3442fd30ea5887a33ca604000d1789f9a60907d0a9b3d2f29ab37966a3ff8b9574a22414307c22309d1ea2d2b0e15f4eb8ec606717d2b24ca1dc496c
@@ -0,0 +1,20 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ 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
@@ -0,0 +1,44 @@
1
+ name: Dry-Behaviour Gem
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - master
7
+ push:
8
+ branches:
9
+ - master
10
+
11
+ jobs:
12
+ build:
13
+ name: Build + Publish
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - uses: actions/checkout@master
18
+ - name: Set up Ruby 2.3.8
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ version: 2.3.8
22
+
23
+ - name: Publish to GPR
24
+ run: |
25
+ mkdir -p $HOME/.gem
26
+ touch $HOME/.gem/credentials
27
+ chmod 0600 $HOME/.gem/credentials
28
+ printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
29
+ gem build *.gemspec
30
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
31
+ env:
32
+ GEM_HOST_API_KEY: ${{secrets.GPR_AUTH_TOKEN}}
33
+ OWNER: username
34
+
35
+ - name: Publish to RubyGems
36
+ run: |
37
+ mkdir -p $HOME/.gem
38
+ touch $HOME/.gem/credentials
39
+ chmod 0600 $HOME/.gem/credentials
40
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
41
+ gem build *.gemspec
42
+ gem push *.gem
43
+ env:
44
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
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.
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = []
26
26
  spec.require_paths = ['lib']
27
27
 
28
- spec.add_development_dependency 'bundler', '~> 1.14'
28
+ spec.add_development_dependency 'bundler', '> 1.10'
29
29
  spec.add_development_dependency 'awesome_print', '~> 1.7'
30
30
  spec.add_development_dependency 'rake', '~> 12.0'
31
31
  spec.add_development_dependency 'benchmark-ips', '~> 2.7'
@@ -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
@@ -124,12 +136,12 @@ module Dry
124
136
  end.each do |m|
125
137
  target = [target] unless target.is_a?(Array)
126
138
  target.each do |tgt|
139
+ params = mod.method(m).parameters.reject { |_, v| v.to_s[/\A♿_/] }
140
+ proto = BlackTie.protocols[protocol]
127
141
  ok =
128
142
  mds.map(&:first).include?(m) ||
129
- [
130
- BlackTie.protocols[protocol][m],
131
- mod.method(m).parameters.reject { |_, v| v.to_s[/\A♿_/] }
132
- ].map(&:first).reduce(:==)
143
+ ((proto[m] == {} || proto[:__implicit_inheritance__]) && [[:req], [:rest]].include?(params.map(&:first))) ||
144
+ [proto[m], params].map { |args| args.map(&:first) }.reduce(:==)
133
145
 
134
146
  # TODO[1.0] raise NotImplemented(:arity)
135
147
  BlackTie.Logger.warn(
@@ -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.1'.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.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Matiushkin
@@ -10,22 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-06-03 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
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ">"
20
20
  - !ruby/object:Gem::Version
21
- version: '1.14'
21
+ version: '1.10'
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - ">"
27
27
  - !ruby/object:Gem::Version
28
- version: '1.14'
28
+ version: '1.10'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: awesome_print
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -105,11 +105,13 @@ executables: []
105
105
  extensions: []
106
106
  extra_rdoc_files: []
107
107
  files:
108
+ - ".github/workflows/ci.yml"
109
+ - ".github/workflows/gempush.yml"
108
110
  - ".gitignore"
109
111
  - ".rspec"
110
112
  - ".rubocop.yml"
111
113
  - ".rubocop_todo.yml"
112
- - ".travis.yml"
114
+ - ".tool-versions"
113
115
  - CODE_OF_CONDUCT.md
114
116
  - Gemfile
115
117
  - LICENSE.txt
@@ -148,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
150
  version: '0'
149
151
  requirements: []
150
152
  rubyforge_project:
151
- rubygems_version: 2.4.8
153
+ rubygems_version: 2.5.2.3
152
154
  signing_key:
153
155
  specification_version: 4
154
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