delivered 0.2.0 → 0.3.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
  SHA256:
3
- metadata.gz: 23b613f6dd8b19b06d0ca874c1a4f7408708f18b88e05d53b683693b27a20a04
4
- data.tar.gz: 1380e56b87e1fa5b534b5bd6645dc1d965dec1c81021e042c4fc7f031aafdae2
3
+ metadata.gz: c2cc2a244302acba122bf449caa221233453955568ca1a7c42f9a4c66e75093a
4
+ data.tar.gz: 2c6033b4adee7756b8fb7bbb9ff0cac83bbe7f42e35220eb9a24857c17e2aa7e
5
5
  SHA512:
6
- metadata.gz: ef984b3f51256ace952efaac631986a500c121408a42f544f6f9c4c296d2d88e2cc909452232bbdb498b4177ead3b910139205105c4137180c56dfcca2297f28
7
- data.tar.gz: 17d2eaeb8cc23bfe69dd3f76b7b33d09d967f0f87d81221209c4b09c6cbd3777ed8ea45d4fd62ad119155a7bd1cd1aba8476677d022a6b24afb23032ff9dd423
6
+ metadata.gz: 3adf4d4bb048a39a00e331e598814998fffe28673702d08bba181cd574f521b3f2d164725c5fe61d349c85c960c32a59d98bb8855ff0f26db6ad5bd74123ae4e
7
+ data.tar.gz: 735bde97671a2e2d69238b5363de35971ecb1a7ab4003e2352c560231bd461b712a3e652bd01c9b02cf067d5d8b2a856baf6b8709621c5f8e34b0eb94c692e9f
data/Gemfile.lock CHANGED
@@ -1,24 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- delivered (0.2.0)
4
+ delivered (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  amazing_print (1.6.0)
10
10
  ast (2.4.2)
11
- debug (1.9.1)
11
+ debug (1.9.2)
12
12
  irb (~> 1.10)
13
13
  reline (>= 0.3.8)
14
14
  io-console (0.7.2)
15
- irb (1.12.0)
16
- rdoc
15
+ irb (1.13.1)
16
+ rdoc (>= 4.0.0)
17
17
  reline (>= 0.4.2)
18
- json (2.7.1)
18
+ json (2.7.2)
19
19
  language_server-protocol (3.17.0.3)
20
20
  parallel (1.24.0)
21
- parser (3.3.0.5)
21
+ parser (3.3.1.0)
22
22
  ast (~> 2.4.1)
23
23
  racc
24
24
  psych (5.1.2)
@@ -27,11 +27,12 @@ GEM
27
27
  rainbow (3.1.1)
28
28
  rdoc (6.6.3.1)
29
29
  psych (>= 4.0.0)
30
- regexp_parser (2.9.0)
31
- reline (0.5.0)
30
+ regexp_parser (2.9.2)
31
+ reline (0.5.7)
32
32
  io-console (~> 0.5)
33
- rexml (3.2.6)
34
- rubocop (1.62.1)
33
+ rexml (3.2.8)
34
+ strscan (>= 3.0.9)
35
+ rubocop (1.63.5)
35
36
  json (~> 2.3)
36
37
  language_server-protocol (>= 3.17.0)
37
38
  parallel (~> 1.10)
@@ -42,11 +43,12 @@ GEM
42
43
  rubocop-ast (>= 1.31.1, < 2.0)
43
44
  ruby-progressbar (~> 1.7)
44
45
  unicode-display_width (>= 2.4.0, < 3.0)
45
- rubocop-ast (1.31.2)
46
- parser (>= 3.3.0.4)
46
+ rubocop-ast (1.31.3)
47
+ parser (>= 3.3.1.0)
47
48
  ruby-progressbar (1.13.0)
48
49
  stringio (3.1.0)
49
- sus (0.24.6)
50
+ strscan (3.1.0)
51
+ sus (0.25.0)
50
52
  unicode-display_width (2.5.0)
51
53
 
52
54
  PLATFORMS
data/README.md CHANGED
@@ -73,6 +73,15 @@ sig validate: T.Boolean
73
73
  def create(validate:); end
74
74
  ```
75
75
 
76
+ #### `RespondTo`
77
+
78
+ Value **MUST** be respond to the given method(s).
79
+
80
+ ```ruby
81
+ sig name: T.RespondTo(:to_s)
82
+ def create(name:); end
83
+ ```
84
+
76
85
  #### `Any`
77
86
 
78
87
  Value **MUST** be any of the given list of values, that is, the value must be one of the given list.
@@ -34,7 +34,7 @@ module Delivered
34
34
  args[i] => ^arg
35
35
  rescue NoMatchingPatternError => e
36
36
  raise Delivered::ArgumentError,
37
- "`#{cname}` expected `#{arg}` as positional arg #{i}, but received " \
37
+ "`#{cname}` expected #{arg.inspect} as argument #{i}, but received " \
38
38
  "`#{args[i].inspect}`",
39
39
  caller, cause: e
40
40
  end
@@ -43,8 +43,8 @@ module Delivered
43
43
  value => ^(sig_kwargs[key])
44
44
  rescue NoMatchingPatternError => e
45
45
  raise Delivered::ArgumentError,
46
- "`#{cname}` expected `#{sig_kwargs[key]}` as keyword arg :#{key}, but received " \
47
- "`#{value.inspect}`",
46
+ "`#{cname}` expected #{sig_kwargs[key].inspect} as keyword argument :#{key}, " \
47
+ "but received `#{value.inspect}`",
48
48
  caller, cause: e
49
49
  end
50
50
 
@@ -58,7 +58,8 @@ module Delivered
58
58
  result => ^returns unless returns.nil?
59
59
  rescue NoMatchingPatternError => e
60
60
  raise Delivered::ArgumentError,
61
- "`#{cname}` expected to return `#{returns}`, but returned `#{result.inspect}`",
61
+ "`#{cname}` expected to return #{returns.inspect}, " \
62
+ "but returned `#{result.inspect}`",
62
63
  caller, cause: e
63
64
  end
64
65
 
@@ -6,16 +6,32 @@ module Delivered
6
6
  @types = types
7
7
  end
8
8
 
9
+ def inspect = "Any(#{@types.map(&:inspect).join(', ')})"
10
+
9
11
  def ===(value)
10
12
  @types.empty? ? true : @types.any? { |type| type === value }
11
13
  end
12
14
  end
13
15
 
16
+ class RespondToType
17
+ def initialize(*methods)
18
+ @methods = methods
19
+ end
20
+
21
+ def inspect = "RespondTo(#{@methods.map(&:inspect).join(', ')})"
22
+
23
+ def ===(value)
24
+ @methods.all? { |m| value.respond_to?(m) }
25
+ end
26
+ end
27
+
14
28
  class NilableType
15
29
  def initialize(type = nil)
16
30
  @type = type
17
31
  end
18
32
 
33
+ def inspect = "Nilable(#{@type&.inspect || 'Any'})"
34
+
19
35
  def ===(value)
20
36
  (@type.nil? ? true : nil === value) || @type === value
21
37
  end
@@ -26,6 +42,8 @@ module Delivered
26
42
  freeze
27
43
  end
28
44
 
45
+ def inspect = 'Boolean'
46
+
29
47
  def ===(value)
30
48
  [true, false].include?(value)
31
49
  end
@@ -35,6 +53,7 @@ module Delivered
35
53
  module_function
36
54
 
37
55
  def Nilable(type = nil) = NilableType.new(type)
56
+ def RespondTo(*methods) = RespondToType.new(*methods)
38
57
  def Any(*types) = AnyType.new(*types)
39
58
  def Boolean = BooleanType.new
40
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Delivered
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
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.2.0
4
+ version: 0.3.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-04-04 00:00:00.000000000 Z
11
+ date: 2024-05-17 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.7
52
+ rubygems_version: 3.5.9
53
53
  signing_key:
54
54
  specification_version: 4
55
55
  summary: Simple runtime type checking for Ruby method signatures