Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soutaro/rbs-inline
Inline RBS type declaration
https://github.com/soutaro/rbs-inline
Last synced: 22 days ago
JSON representation
Inline RBS type declaration
- Host: GitHub
- URL: https://github.com/soutaro/rbs-inline
- Owner: soutaro
- License: mit
- Created: 2024-04-04T08:24:47.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-08-08T18:36:19.000Z (3 months ago)
- Last Synced: 2024-08-09T10:33:38.855Z (3 months ago)
- Language: Ruby
- Size: 307 KB
- Stars: 186
- Watchers: 10
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# RBS::Inline
RBS::Inline allows embedding RBS type declarations into Ruby code as comments. You can declare types, write the implementation, and verifies they are consistent without leaving the editor opening the Ruby code.
> [!IMPORTANT]
> The syntax is experimental. We are still seeking the best syntax with your feedbacks.> [!IMPORTANT]
> This gem is a prototype for testing. We plan to merge this feature to rbs-gem and deprecate rbs-inline gem after that.> [!NOTE]
> Use Steep >= `1.8.0.dev` to avoid the conflicts on `#:` syntax.Here is a quick example of embedded declarations.
```rb
# rbs_inline: enabledclass Person
attr_reader :name #: Stringattr_reader :addresses #: Array[String]
# @rbs name: String
# @rbs addresses: Array[String]
# @rbs return: void
def initialize(name:, addresses:)
@name = name
@addresses = addresses
enddef to_s #: String
"Person(name = #{name}, addresses = #{addresses.join(", ")})"
end# @rbs &block: (String) -> void
def each_address(&block) #: void
addresses.each(&block)
end
end
```This is equivalent to the following RBS type definition.
```rbs
class Person
attr_reader name: Stringattr_reader addresses: Array[String]
def initialize: (name: String, addresses: Array[String]) -> void
def to_s: () -> String
def each_address: () { (String) -> void } -> void
end
```## Installation
Install the gem and add to the application's Gemfile by executing:
$ bundle add rbs-inline --require=false
Note that the `--require=false` is important to avoid having type definition dependencies to this gem, which is usually unnecessary.
You can of course add a `gem` call in your Gemfile yourself.
```rb
gem 'rbs-inline', require: false
```If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install rbs-inline
## Usage
The gem works as a transpiler from annotated Ruby code to RBS files. Run `rbs-inline` command to generate RBS files, and use the generated files with Steep, or any tools which supports RBS type definitions.
```sh
# Print generated RBS files
$ bundle exec rbs-inline lib# Save generated RBS files under sig/generated
$ bundle exec rbs-inline --output lib
```You may want to use `fswatch` or likes to automatically generate RBS files when you edit the Ruby code.
$ fswatch -0 lib | xargs -0 -n1 bundle exec rbs-inline --output
## More materials
[Our wiki](https://github.com/soutaro/rbs-inline/wiki) has some materials to read.
* [Syntax guide](https://github.com/soutaro/rbs-inline/wiki/Syntax-guide) explains more details of the syntax and annotations.
* [Roadmap](https://github.com/soutaro/rbs-inline/wiki/Roadmap) explains some of the missing features and our plans.
* [Snippets](https://github.com/soutaro/rbs-inline/wiki/Snippets) helps setting up your editors.## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/soutaro/rbs-inline. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/soutaro/rbs-inline/blob/main/CODE_OF_CONDUCT.md).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the Rbs::Inline project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/soutaro/rbs-inline/blob/main/CODE_OF_CONDUCT.md).