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.
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
+ [![Development Status](https://github.com/ioquatix/types/workflows/Test/badge.svg)](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.2.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
- MIIEhDCCAuygAwIBAgIBATANBgkqhkiG9w0BAQsFADA3MTUwMwYDVQQDDCxzYW11
14
- ZWwud2lsbGlhbXMvREM9b3Jpb250cmFuc2Zlci9EQz1jby9EQz1uejAeFw0yMTA4
15
- MTYwNjMzNDRaFw0yMjA4MTYwNjMzNDRaMDcxNTAzBgNVBAMMLHNhbXVlbC53aWxs
16
- aWFtcy9EQz1vcmlvbnRyYW5zZmVyL0RDPWNvL0RDPW56MIIBojANBgkqhkiG9w0B
17
- AQEFAAOCAY8AMIIBigKCAYEAyXLSS/cw+fXJ5e7hi+U/TeChPWeYdwJojDsFY1xr
18
- xvtqbTTL8gbLHz5LW3QD2nfwCv3qTlw0qI3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8vZGhp+hz+8Q573tAR89y9YJBdYM
25
+ zp0FM4zwMNEUwgfRzv1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW
26
+ xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
27
+ BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs
28
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs
29
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE
30
+ cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl
31
+ xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/
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: 2022-07-01 00:00:00.000000000 Z
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
- post_install_message:
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: '0'
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.3.7
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