types 0.2.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
- checksums.yaml.gz.sig +0 -0
- data/agent.md +47 -0
- data/context/usage.md +195 -0
- data/lib/types/any.rb +41 -43
- data/lib/types/array.rb +33 -20
- data/lib/types/block.rb +28 -20
- data/lib/types/boolean.rb +25 -20
- data/lib/types/class.rb +46 -22
- data/lib/types/decimal.rb +25 -24
- data/lib/types/float.rb +24 -20
- data/lib/types/generic.rb +17 -22
- data/lib/types/hash.rb +32 -20
- data/lib/types/integer.rb +24 -20
- data/lib/types/interface.rb +100 -0
- data/lib/types/lambda.rb +23 -21
- data/lib/types/method.rb +35 -22
- data/lib/types/named.rb +106 -0
- data/lib/types/nil.rb +24 -20
- data/lib/types/numeric.rb +13 -20
- data/lib/types/string.rb +23 -20
- data/lib/types/symbol.rb +23 -20
- data/lib/types/tuple.rb +32 -21
- data/lib/types/version.rb +3 -20
- data/lib/types.rb +52 -38
- data/license.md +21 -0
- data/readme.md +71 -0
- data.tar.gz.sig +0 -0
- metadata +37 -34
- metadata.gz.sig +0 -0
data/readme.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Types
|
2
|
+
|
3
|
+
Provides abstract types for the Ruby programming language which can used for documentation and evaluation purposes.
|
4
|
+
|
5
|
+
[](https://github.com/ioquatix/types/actions?workflow=Test)
|
6
|
+
|
7
|
+
## Motivation
|
8
|
+
|
9
|
+
I've been working on documentation tools and Ruby has several implementations for adding type information. However, I've feel like we've over-complicated the language of types and I'd like something simpler and more compatible with the Ruby language.
|
10
|
+
|
11
|
+
The original design started in [bake](https://github.com/ioquatix/bake) which uses `@parameter name [Signature] description` comments to document the types of parameters. The command-line interface of bake uses the type signature to coerce string arguments to the desired type. This has been a useful strategy to reduce code duplication and to make the code more readable.
|
12
|
+
|
13
|
+
Subsequently, I started using these type signatures in [decode](https://github.com/ioquatix/decode) which uses similar `@parameter` comments. This information is fed into [utopia-project](https://github.com/socketry/utopia-project) which can present this information as part of the generated documentation.
|
14
|
+
|
15
|
+
The expressions possible with this gem are a subset of all possible expressions in Ruby's type system. This is by design. At some point in the future, it is likely we will automate conversion of type signatures to the RBS compatible type signature files. This will allow us to use the same type signatures in the documentation and in the code.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
``` shell
|
20
|
+
bundle add types
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Parsing type signatures can be done using {ruby Types.parse} which returns a object that represents the given type, e.g.
|
26
|
+
|
27
|
+
``` ruby
|
28
|
+
string_type = Types.parse("String")
|
29
|
+
string_type # => Types::String
|
30
|
+
|
31
|
+
array_type = Types.parse("Array(String)")
|
32
|
+
array_type.class # => Types::Array
|
33
|
+
|
34
|
+
hash_type = Types.parse("Hash(String, Integer)")
|
35
|
+
hash_type.key_type # => Types::String
|
36
|
+
hash_type.value_type # => Types::Integer
|
37
|
+
```
|
38
|
+
|
39
|
+
You can generate a string representation of a type too:
|
40
|
+
|
41
|
+
``` ruby
|
42
|
+
# A lambda that takes an Integer as an argument and returns an Integer:
|
43
|
+
lambda_type = Types.parse("Lambda(Integer, returns: Integer)")
|
44
|
+
lambda_type.to_s # => "Lambda(Integer, returns: Integer)"
|
45
|
+
```
|
46
|
+
|
47
|
+
### String Parsing
|
48
|
+
|
49
|
+
In addition, you can coerce strings into strongly typed values:
|
50
|
+
|
51
|
+
``` ruby
|
52
|
+
array_type = Types.parse("Array(String)")
|
53
|
+
array_type.parse("'foo', 'bar'") # => ["foo", "bar"]
|
54
|
+
```
|
55
|
+
|
56
|
+
This can be useful for argument parsing.
|
57
|
+
|
58
|
+
### Documentation
|
59
|
+
|
60
|
+
This gem is designed to be integrated into documentation tools. It provides a way to document the types of parameters and return values of a function. This information is stored in `@parameter` and `@returns` comments.
|
61
|
+
|
62
|
+
``` ruby
|
63
|
+
# Double the value of a number.
|
64
|
+
# @parameter value [Numeric] The value to double.
|
65
|
+
# @returns [Numeric] The doubled value.
|
66
|
+
def double(value)
|
67
|
+
return value * 2
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
The motivation for discrete parameter and return types is to make integration with documentation tools easier. Specifically, language servers can use this information to provide context sensitive type information and documentation which is hard to do with existing formats like `rdoc`.
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: types
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain:
|
11
10
|
- |
|
12
11
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
12
|
+
MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
|
13
|
+
ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
|
14
|
+
CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
|
15
|
+
MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
|
16
|
+
MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
|
17
|
+
bzESMBAGCgmSJomT8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t9rNeXmnW/
|
32
|
+
c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
|
33
|
+
8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
|
34
|
+
JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
|
35
|
+
eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
|
36
|
+
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
37
|
+
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date:
|
39
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
40
40
|
dependencies: []
|
41
|
-
description:
|
42
|
-
email:
|
43
41
|
executables: []
|
44
42
|
extensions: []
|
45
43
|
extra_rdoc_files: []
|
46
44
|
files:
|
45
|
+
- agent.md
|
46
|
+
- context/usage.md
|
47
47
|
- lib/types.rb
|
48
48
|
- lib/types/any.rb
|
49
49
|
- lib/types/array.rb
|
@@ -55,20 +55,24 @@ files:
|
|
55
55
|
- lib/types/generic.rb
|
56
56
|
- lib/types/hash.rb
|
57
57
|
- lib/types/integer.rb
|
58
|
+
- lib/types/interface.rb
|
58
59
|
- lib/types/lambda.rb
|
59
60
|
- lib/types/method.rb
|
61
|
+
- lib/types/named.rb
|
60
62
|
- lib/types/nil.rb
|
61
63
|
- lib/types/numeric.rb
|
62
64
|
- lib/types/string.rb
|
63
65
|
- lib/types/symbol.rb
|
64
66
|
- lib/types/tuple.rb
|
65
67
|
- lib/types/version.rb
|
68
|
+
- license.md
|
69
|
+
- readme.md
|
66
70
|
homepage: https://github.com/ioquatix/types
|
67
71
|
licenses:
|
68
72
|
- MIT
|
69
73
|
metadata:
|
70
74
|
funding_uri: https://github.com/sponsors/ioquatix/
|
71
|
-
|
75
|
+
source_code_uri: https://github.com/ioquatix/types.git
|
72
76
|
rdoc_options: []
|
73
77
|
require_paths:
|
74
78
|
- lib
|
@@ -76,15 +80,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
80
|
requirements:
|
77
81
|
- - ">="
|
78
82
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
83
|
+
version: '3.2'
|
80
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
85
|
requirements:
|
82
86
|
- - ">="
|
83
87
|
- !ruby/object:Gem::Version
|
84
88
|
version: '0'
|
85
89
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
87
|
-
signing_key:
|
90
|
+
rubygems_version: 3.6.7
|
88
91
|
specification_version: 4
|
89
92
|
summary: A simple human-readable and Ruby-parsable type library.
|
90
93
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|