delivered 0.3.0 → 0.4.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 +4 -4
- data/Gemfile.lock +5 -5
- data/README.md +10 -0
- data/lib/delivered/signature.rb +15 -15
- data/lib/delivered/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: bd1eeeeaa704a08c1b4c834b24ba5623409da015b9697df7653cd60502edd8c3
|
4
|
+
data.tar.gz: 7fbce031535260897742c0f38100b23b0e62431f85dcd0f40c5b5a062a1f982a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cca910f20d4d8cc948912346ff1f2c20add1e0fb7b7ba3bdaa42e81702195290b84670220579e6e6359a619e2f94f4bf4460fd0a2c9ad7227d39b2f84c42896
|
7
|
+
data.tar.gz: 23ad19572356a722b933db7253810b212120f1d9d47242a4fe56b5c6009d51164d6035ede779ee9d37758e9c6d3b235d18c75f553a5b8e09bf80318c59caac64
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
delivered (0.
|
4
|
+
delivered (0.4.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -23,16 +23,16 @@ GEM
|
|
23
23
|
racc
|
24
24
|
psych (5.1.2)
|
25
25
|
stringio
|
26
|
-
racc (1.
|
26
|
+
racc (1.8.0)
|
27
27
|
rainbow (3.1.1)
|
28
|
-
rdoc (6.
|
28
|
+
rdoc (6.7.0)
|
29
29
|
psych (>= 4.0.0)
|
30
30
|
regexp_parser (2.9.2)
|
31
|
-
reline (0.5.
|
31
|
+
reline (0.5.8)
|
32
32
|
io-console (~> 0.5)
|
33
33
|
rexml (3.2.8)
|
34
34
|
strscan (>= 3.0.9)
|
35
|
-
rubocop (1.
|
35
|
+
rubocop (1.64.0)
|
36
36
|
json (~> 2.3)
|
37
37
|
language_server-protocol (>= 3.17.0)
|
38
38
|
parallel (~> 1.10)
|
data/README.md
CHANGED
@@ -26,6 +26,16 @@ end
|
|
26
26
|
If an invalid argument is given to `User#create`, for example, if `age` is a `String` instead of
|
27
27
|
the required `Integer`, a `Delivered::ArgumentError` exception will be raised.
|
28
28
|
|
29
|
+
### Single and Double Splat Arguments
|
30
|
+
|
31
|
+
You can use single and double splats in your method signatures, and Delivered will pass them through
|
32
|
+
without checking, while still checking the other named positional and keyword arguments.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
sig String
|
36
|
+
def create(name, *args, foo:, **kwargs); end
|
37
|
+
```
|
38
|
+
|
29
39
|
### Return Types
|
30
40
|
|
31
41
|
You can also check the return value of the method by passing a Hash with an Array as the key, and
|
data/lib/delivered/signature.rb
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
module Delivered
|
4
4
|
module Signature
|
5
5
|
def sig(*sig_args, **sig_kwargs, &return_blk)
|
6
|
-
# ap [sig_args, sig_kwargs, return_blk]
|
7
|
-
|
8
6
|
# Block return
|
9
7
|
returns = return_blk&.call
|
10
8
|
|
@@ -20,15 +18,13 @@ module Delivered
|
|
20
18
|
sig_kwargs = sig_args.pop if sig_args.last.is_a?(Hash)
|
21
19
|
end
|
22
20
|
|
23
|
-
# ap
|
21
|
+
# ap(sig_args:, sig_kwargs:)
|
24
22
|
|
25
23
|
meta = class << self; self; end
|
26
24
|
sig_check = lambda do |klass, class_method, name, *args, **kwargs, &block| # rubocop:disable Metrics/BlockLength
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
"#{klass.class.name}##{name}"
|
31
|
-
end
|
25
|
+
# ap(args:, kwargs:, params: klass.method(:"__#{name}").parameters)
|
26
|
+
|
27
|
+
cname = class_method ? "#{klass.name}.#{name}" : "#{klass.class.name}##{name}"
|
32
28
|
|
33
29
|
sig_args.each.with_index do |arg, i|
|
34
30
|
args[i] => ^arg
|
@@ -39,13 +35,15 @@ module Delivered
|
|
39
35
|
caller, cause: e
|
40
36
|
end
|
41
37
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
38
|
+
unless sig_kwargs.empty?
|
39
|
+
kwargs.each do |key, value|
|
40
|
+
value => ^(sig_kwargs[key])
|
41
|
+
rescue NoMatchingPatternError => e
|
42
|
+
raise Delivered::ArgumentError,
|
43
|
+
"`#{cname}` expected #{sig_kwargs[key].inspect} as keyword argument :#{key}, " \
|
44
|
+
"but received `#{value.inspect}`",
|
45
|
+
caller, cause: e
|
46
|
+
end
|
49
47
|
end
|
50
48
|
|
51
49
|
result = if block
|
@@ -66,6 +64,7 @@ module Delivered
|
|
66
64
|
result
|
67
65
|
end
|
68
66
|
|
67
|
+
# Instance method redefinition
|
69
68
|
meta.send :define_method, :method_added do |name|
|
70
69
|
meta.send :remove_method, :method_added
|
71
70
|
meta.send :remove_method, :singleton_method_added
|
@@ -76,6 +75,7 @@ module Delivered
|
|
76
75
|
end
|
77
76
|
end
|
78
77
|
|
78
|
+
# Class method redefinition
|
79
79
|
meta.send :define_method, :singleton_method_added do |name|
|
80
80
|
next if name == :singleton_method_added
|
81
81
|
|
data/lib/delivered/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delivered
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Moss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -49,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '0'
|
51
51
|
requirements: []
|
52
|
-
rubygems_version: 3.5.
|
52
|
+
rubygems_version: 3.5.10
|
53
53
|
signing_key:
|
54
54
|
specification_version: 4
|
55
55
|
summary: Simple runtime type checking for Ruby method signatures
|