decode 0.24.6 → 0.26.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/context/documentation-coverage.md +254 -0
- data/context/getting-started.md +34 -222
- data/context/index.yaml +22 -0
- data/context/ruby-documentation.md +59 -26
- data/lib/decode/comment/constant.rb +1 -1
- data/lib/decode/comment/example.rb +62 -0
- data/lib/decode/comment/option.rb +1 -1
- data/lib/decode/comment/tag.rb +1 -0
- data/lib/decode/documentation.rb +1 -0
- data/lib/decode/language/generic.rb +2 -0
- data/lib/decode/language/ruby/class.rb +5 -0
- data/lib/decode/language/ruby/generic.rb +2 -0
- data/lib/decode/language/ruby/parser.rb +2 -2
- data/lib/decode/rbs/type.rb +2 -2
- data/lib/decode/scope.rb +1 -1
- data/lib/decode/version.rb +1 -1
- data/readme.md +11 -1
- data/releases.md +8 -0
- data.tar.gz.sig +1 -4
- metadata +5 -4
- metadata.gz.sig +0 -0
- data/context/coverage.md +0 -325
- data/context/types.md +0 -127
data/context/types.md
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
# Setting Up RBS Types and Steep Type Checking for Ruby Gems
|
|
2
|
-
|
|
3
|
-
This guide covers the process for establishing robust type checking in Ruby gems using RBS and Steep, focusing on automated generation from source documentation and proper validation.
|
|
4
|
-
|
|
5
|
-
## Core Process
|
|
6
|
-
|
|
7
|
-
### Documentation-Driven RBS Generation
|
|
8
|
-
|
|
9
|
-
Generate RBS files from documentation:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
bake decode:rbs:generate lib > sig/example/gem.rbs`
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
At a minimum, add `@parameter`, `@attribute` and `@returns` documentation to all public methods.
|
|
16
|
-
|
|
17
|
-
#### Parametric Types
|
|
18
|
-
|
|
19
|
-
Use `@rbs generic` comments to define type parameters for classes and modules:
|
|
20
|
-
|
|
21
|
-
```ruby
|
|
22
|
-
# @rbs generic T
|
|
23
|
-
class Container
|
|
24
|
-
# @parameter item [T] The item to store
|
|
25
|
-
def initialize(item)
|
|
26
|
-
@item = item
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# @returns [T] The stored item
|
|
30
|
-
def get
|
|
31
|
-
@item
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Use `@rbs` comments for parametric method signatures:
|
|
37
|
-
|
|
38
|
-
```ruby
|
|
39
|
-
# From above:
|
|
40
|
-
class Container
|
|
41
|
-
# @rbs () { (T) -> void } -> void
|
|
42
|
-
def each
|
|
43
|
-
yield @item
|
|
44
|
-
end
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
#### Interfaces
|
|
48
|
-
|
|
49
|
-
Create interfaces in `sig/example/gem/interface.rbs`:
|
|
50
|
-
|
|
51
|
-
```rbs
|
|
52
|
-
module Example
|
|
53
|
-
module Gem
|
|
54
|
-
interface _Interface
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
You can use the interface in `@parameter`, `@attribute` and `@returns` types.
|
|
61
|
-
|
|
62
|
-
### Testing
|
|
63
|
-
|
|
64
|
-
Run tests using the `steep` gem.
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
steep check
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
**Process**: Start with basic generation, then refine based on Steep feedback.
|
|
71
|
-
|
|
72
|
-
1. Generate initial RBS from documentation
|
|
73
|
-
2. Run `steep check lib` to identify issues
|
|
74
|
-
3. Fix structural problems (inheritance, missing docs)
|
|
75
|
-
4. Iterate until clean validation
|
|
76
|
-
|
|
77
|
-
### Deploymnet
|
|
78
|
-
|
|
79
|
-
Make sure `bake-test-types` is added to the `test` group in `gems.rb` (or `Gemfile`).
|
|
80
|
-
|
|
81
|
-
```ruby
|
|
82
|
-
group :test do
|
|
83
|
-
# ...
|
|
84
|
-
gem "bake-test"
|
|
85
|
-
gem "bake-test-external"
|
|
86
|
-
gem "bake-test-types"
|
|
87
|
-
# ...
|
|
88
|
-
end
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Then, create `.github/workflows/test-types.yaml`:
|
|
92
|
-
|
|
93
|
-
```yaml
|
|
94
|
-
name: Test Types
|
|
95
|
-
|
|
96
|
-
on: [push, pull_request]
|
|
97
|
-
|
|
98
|
-
permissions:
|
|
99
|
-
contents: read
|
|
100
|
-
|
|
101
|
-
env:
|
|
102
|
-
CONSOLE_OUTPUT: XTerm
|
|
103
|
-
|
|
104
|
-
jobs:
|
|
105
|
-
test:
|
|
106
|
-
name: ${{matrix.ruby}} on ${{matrix.os}}
|
|
107
|
-
runs-on: ${{matrix.os}}-latest
|
|
108
|
-
|
|
109
|
-
strategy:
|
|
110
|
-
matrix:
|
|
111
|
-
os:
|
|
112
|
-
- ubuntu
|
|
113
|
-
|
|
114
|
-
ruby:
|
|
115
|
-
- "3.4"
|
|
116
|
-
|
|
117
|
-
steps:
|
|
118
|
-
- uses: actions/checkout@v4
|
|
119
|
-
- uses: ruby/setup-ruby@v1
|
|
120
|
-
with:
|
|
121
|
-
ruby-version: ${{matrix.ruby}}
|
|
122
|
-
bundler-cache: true
|
|
123
|
-
|
|
124
|
-
- name: Run tests
|
|
125
|
-
timeout-minutes: 10
|
|
126
|
-
run: bundle exec bake test:types
|
|
127
|
-
```
|