Add rails-generator for rails gems
Proposal
I have implemented a generator for rails gems.
I propose to use rails-generator to manage RBS for rails gems.
Simply run the rake command to generate an RBS with the following gems and versions from rails gem source code.
- gems
- actionpack
- actionview
- activejob
- activemodel
- activerecord
- activestorage
- activesupport
- railties
- versions
- 6.0
- 6.1
- 7.0
I have not included it in this PR because generating all RBSs would result in very large differences. Please review the generator only in this PR. The generated RBS can be viewed at https://github.com/ksss/gem_rbs_collection/tree/rails-generator-full .
Problem
I know there is a gems/railties/6.0/_scripts/generate.rb.
However, currently *-generated.rbs file is edited without generate.rb and the definition cannot be overwritten.
Also, static analysis cannot handle dynamically added methods and mixins.
Solution
So, based on generate.rb, I have further improved it, added various features, added tests, and made it into a gem package.
https://github.com/ksss/orthoses https://github.com/ksss/orthoses-rails
These gems are like tapioca for sorbet.
This generator makes RBS as automated as possible and allows to add definitions by RBS file.
The following features are currently available for automation, and additional features are under development.
- Dynamic mixins, attr methods, and constants
- Inheritance via
DelegateClass()like Tempfile - Methods dynamically added by
class_attribute,mattr_accessorandconfig_accessor. - Delegate methods to
ActiveSupport::TimeWithZonefromTimebymethod_missing. - Method definition by
delegatewhen the original definition exists. - Split railties mixin to
railtiesfor gem dependency.
We put these functions on the base of $ rbs prototype rb and merge RBS in a separate file.
Roadmap
First We will add the RBS created by the generator in rails 7.0 to gem_rbs_collection. Then replace the existing 6.0, 6.1 with the RBS created by the generator. Once the functionality is added to the generator, We will regenerate it all together. If more rails versions are added, we will generate them each time.
Operation
If we want to add a new RBS definition, we consider an operation that makes changes to rails-generator/known_sig and regenerates it.
The reason why the RBS is necessary for the generator is that it needs to know the type of the target when delegating by delegate or method_missing.
We would like to put the details in rails-generator/README.md.
Review point
-
generators/rails-generator/- README.md
- Operation document.
- Rakefile
- Main generator script using orthoses.
- known_sig/*
- Specified RBS.
- tasks/*
- Rake task for each gems.
- config/*
- Minimum files required to start a rails application.
- README.md
@pocke This is a big change, but I hope you can see it.
Thanks for your PR and sorry for my absence. I'll review this PR this week.
@pocke Many thanks for the confirmation. I have corrected the points raised and updated the code to the latest state. Please check it.
@pocke What is the status of this? I believe that PRs like following will be more manageable in the future by incorporating this change.
- https://github.com/ruby/gem_rbs_collection/pull/277
- https://github.com/ruby/gem_rbs_collection/pull/280
- https://github.com/ruby/gem_rbs_collection/pull/281
I'll close this PR due to the lack of activities.