{"id":13878718,"url":"https://github.com/camertron/gelauto","last_synced_at":"2025-04-04T21:09:13.021Z","repository":{"id":56873700,"uuid":"193561156","full_name":"camertron/gelauto","owner":"camertron","description":"Automatically annotate your code with Sorbet type definitions.","archived":false,"fork":false,"pushed_at":"2024-10-14T05:16:30.000Z","size":46,"stargazers_count":54,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T20:09:07.957Z","etag":null,"topics":["automation","ruby","sorbet","types"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/camertron.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-24T18:49:00.000Z","updated_at":"2025-01-02T06:08:38.000Z","dependencies_parsed_at":"2025-01-18T18:12:59.602Z","dependency_job_id":"353ec812-509c-4272-9446-9c4823f5b0a6","html_url":"https://github.com/camertron/gelauto","commit_stats":{"total_commits":30,"total_committers":3,"mean_commits":10.0,"dds":0.2666666666666667,"last_synced_commit":"3f750d75a22fec1ab4e9b80f89b41d4a97cf94f7"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camertron%2Fgelauto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camertron%2Fgelauto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camertron%2Fgelauto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camertron%2Fgelauto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/camertron","download_url":"https://codeload.github.com/camertron/gelauto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249529,"owners_count":20908212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","ruby","sorbet","types"],"created_at":"2024-08-06T08:01:57.664Z","updated_at":"2025-04-04T21:09:13.001Z","avatar_url":"https://github.com/camertron.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"## gelauto [![Build status](https://github.com/camertron/gelauto/actions/workflows/test.yml/badge.svg)](https://github.com/camertron/gelauto/actions/workflows/test.yml)\n\nAutomatically annotate your code with Sorbet type definitions.\n\n## What is This Thing?\n\nThe wonderful folks at Stripe recently released a static type checker for Ruby called [Sorbet](https://github.com/sorbet/sorbet). It works by examining type signatures placed at the beginning of each method. For example:\n\n```ruby\n# typed: true\n\nclass Car\n  extend T::Sig\n\n  sig { params(num_wheels: Integer) }\n  def initialize(num_wheels)\n    @num_wheels = num_wheels\n  end\n\n  sig { params(speed: Float).returns(T::Boolean) }\n  def drive(speed)\n    true\n  end\nend\n```\n\nAdding these definitions means you get cool stuff like auto-complete and type checking in your editor. Pretty freaking rad.\n\n### Ok, so what is Gelauto?\n\nGelauto is an _auto_-matic way (get it?! lol) of adding Sorbet type signatures to your methods. It works by running your code (for example, your test suite). As your code runs, Gelauto keeps track of the actual types of objects that were passed to your methods as well as the types of objects they return. After gathering the info, Gelauto then (optionally) inserts type signatures into your Ruby files.\n\n## Installation\n\n`gem install gelauto`\n\n## Usage\n\nYou can run Gelauto either via the command line or by adding it to your bundle.\n\n### Command Line Usage\n\nFirst, install the gem by running `gem install gelauto`. That will make the `gelauto` executable available on your system.\n\nGelauto's only subcommand is `run`, which accepts a list of Ruby files to scan for methods and a command to run that will exercise your code.\n\nIn this example, we're going to be running an [RSpec](https://github.com/rspec/rspec) test suite.\nLike most RSpec test suites, let's assume ours is stored in the `spec/` directory (that's the RSpec default too). To run the test suite in `spec/` and add type definitions to our ruby files, we might run the following command:\n\n```bash\ngelauto run --annotate $(find . -name '*.rb') -- bundle exec rspec spec/\n```\n\nYou can also choose to run Gelauto with the `--rbi` flag, which will cause Gelauto to print results to standard output or to the given file in [RBI format](https://sorbet.org/docs/rbi):\n\n```bash\n# print RBI output to STDOUT\ngelauto run --annotate --rbi - $(find . -name '*.rb') -- bundle exec rspec spec/\n\n# write RBI output to a file\ngelauto run --annotate --rbi ./rbi/mylib.rbi $(find . -name '*.rb') -- bundle exec rspec spec/\n```\n\nIn this second example, we're going to be running a minitest test suite. Like most minitest suites, let's assume ours is stored in the `test/` directory (that's the Rails default too). To run the test suite in `test/`, we might run the following command:\n\n```bash\ngelauto run --annotate $(find . -name '*.rb') -- bundle exec rake test/\n```\n\n### Gelauto in your Bundle\n\nIf you would rather run Gelauto as part of your bundle, add it to your Gemfile like so:\n\n```ruby\ngem 'gelauto'\n```\n\nGelauto can be invoked from within your code in one of several ways.\n\n#### Gelauto.discover\n\nWrap code you'd like to run with Gelauto in `Gelauto.discover`:\n\n```ruby\nrequire 'gelauto'\n\nGelauto.paths \u003c\u003c 'path/to/file/i/want/to/annotate.rb'\n\nGelauto.discover do\n  call_some_method(with, some, params)\nend\n\n# loop over files and annotate them\nGelauto.each_absolute_path do |path|\n  Gelauto.annotate_file(path)\nend\n\n# you can also grab a reference to the method cache Gelauto\n# has populated with all the type information it's been able\n# to gather:\nGelauto.method_index\n```\n\n#### Setup and Teardown\n\n`Gelauto.discover` is just syntactic sugar around two methods that start and stop Gelauto's method tracing functionality:\n\n```ruby\nGelauto.setup\n\nbegin\n  call_some_method(with, some, params)\nensure\n  Gelauto.teardown\nend\n```\n\n#### RSpec Helper\n\nGelauto comes with a handy RSpec helper that can do most of this for you. Simply add\n\n```ruby\nrequire 'gelauto/rspec'\n```\n\nto your spec_helper.rb, Rakefile, or wherever RSpec is configured. You'll also need to set the `GELAUTO_FILES` environment variable when running your test suite. For example:\n\n```bash\nGELAUTO_FILES=$(find . -name *.rb) bundle exec rspec\n```\n\nFiles can be separated by spaces, newlines, or commas. If you want Gelauto to annotate them, set `GELAUTO_ANNOTATE` to `true`, eg:\n\n```bash\nGELAUTO_FILES=$(find . -name *.rb) GELAUTO_ANNOTATE=true bundle exec rspec\n```\n\nFinally, set `GELAUTO_RBI=/path/to/output.rbi` to have Gelauto emit an RBI file when the test suite finishes.\n\n#### Minitest Helper\n\nGelauto also comes with a handy Minitest helper. Simply add\n\n```ruby\nrequire 'gelauto/minitest'\n```\n\nto your test_helper.rb (or wherever Minitest is `require`d and configured). The same environment variables described above for RSpec, eg. `GELAUTO_FILES`, `GELAUTO_ANNOTATE`, and `GELAUTO_RBI`, can be used in a Minitest setup.\n\n## How does it Work?\n\nGelauto makes use of Ruby's [TracePoint API](https://ruby-doc.org/core-2.6/TracePoint.html). TracePoint effectively allows Gelauto to receive a notification whenever a Ruby method is called and whenever a method returns. That info combined with method location information gathered from parsing your Ruby files ahead of time allows Gelauto to know a) where methods are located, 2) what arguments they take, 3) the types of those arguments, and 4) the type of the return value.\n\n\"Doesn't that potentially make my code run slower?\" is a question you might ask. Yes. Gelauto adds overhead to literally every Ruby method call, so your code will probably run quite a bit slower. For that reason you probably won't want to enable Gelauto in, for example, a production web application.\n\n## Known Limitations\n\n* Half-baked support for singleton (i.e. static) methods.\n* Gelauto does not annotate Ruby files with `# typed: true` comments or `extend T::Sig`.\n\n## Running Tests\n\n`bundle exec rspec` should do the trick :)\n\n## Contributing\n\nPlease fork this repo and submit a pull request.\n\n## License\n\nLicensed under the MIT license. See LICENSE for details.\n\n## Authors\n\n* Cameron C. Dutro: http://github.com/camertron\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcamertron%2Fgelauto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcamertron%2Fgelauto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcamertron%2Fgelauto/lists"}