{"id":15033176,"url":"https://github.com/sinsoku/rbs-trace","last_synced_at":"2025-10-05T06:00:13.436Z","repository":{"id":255775251,"uuid":"853607476","full_name":"sinsoku/rbs-trace","owner":"sinsoku","description":"RBS::Trace automatically collects argument and return types and saves RBS type declarations as RBS files or comments.","archived":false,"fork":false,"pushed_at":"2025-03-29T16:55:01.000Z","size":175,"stargazers_count":16,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T17:23:29.462Z","etag":null,"topics":["ruby"],"latest_commit_sha":null,"homepage":"","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/sinsoku.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2024-09-07T02:59:20.000Z","updated_at":"2025-03-29T16:55:04.000Z","dependencies_parsed_at":"2025-02-11T16:29:47.363Z","dependency_job_id":"4b255033-d5ec-4e0b-a0ea-f9e1d7bd5950","html_url":"https://github.com/sinsoku/rbs-trace","commit_stats":null,"previous_names":["sinsoku/rbs-trace"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinsoku%2Frbs-trace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinsoku%2Frbs-trace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinsoku%2Frbs-trace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinsoku%2Frbs-trace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sinsoku","download_url":"https://codeload.github.com/sinsoku/rbs-trace/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248113157,"owners_count":21049794,"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":["ruby"],"created_at":"2024-09-24T20:20:19.211Z","updated_at":"2025-10-05T06:00:13.423Z","avatar_url":"https://github.com/sinsoku.png","language":"Ruby","readme":"[![Gem Version](https://badge.fury.io/rb/rbs-trace.svg)](https://badge.fury.io/rb/rbs-trace)\n[![Test](https://github.com/sinsoku/rbs-trace/actions/workflows/test.yml/badge.svg)](https://github.com/sinsoku/rbs-trace/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/sinsoku/rbs-trace/graph/badge.svg?token=rEsPe8Quyu)](https://codecov.io/gh/sinsoku/rbs-trace)\n\n# RBS::Trace\n\nRBS::Trace automatically collects argument and return types and saves RBS type declarations as RBS files or comments.\n\n## Installation\n\nInstall the gem and add to the application's Gemfile by executing:\n\n    $ bundle add rbs-trace\n\nIf bundler is not being used to manage dependencies, install the gem by executing:\n\n    $ gem install rbs-trace\n\n## Usage\n\nFor example, suppose you have the following class:\n\n```ruby\nclass User\n  def initialize(first_name, last_name)\n    @first_name = first_name\n    @last_name = last_name\n  end\n\n  def full_name\n    \"#{@first_name} #{@last_name}\"\n  end\n\n  def say_hello\n    puts \"hi, #{full_name}.\"\n  end\nend\n```\n\nCall target methods within the `enable` method block, and call the `save_comments` method.\n\n```ruby\ntrace = RBS::Trace.new\n\n# Collects the types of methods called in the block.\ntrace.enable do\n  user = User.new(\"Nanoha\", \"Takamachi\")\n  user.say_hello\nend\n\n# Save RBS type declarations as embedded comments\ntrace.save_comments\n```\n\nAutomatically insert comments into the file.\n\n```ruby\nclass User\n  # @rbs (String, String) -\u003e void\n  def initialize(first_name, last_name)\n    @first_name = first_name\n    @last_name = last_name\n  end\n\n  # @rbs () -\u003e String\n  def full_name\n    \"#{@first_name} #{@last_name}\"\n  end\n\n  # @rbs () -\u003e void\n  def say_hello\n    puts \"hi, #{full_name}.\"\n  end\nend\n```\n\n## Integration\n\n### RSpec\n\nAdd the following code to `spec/support/rbs_trace.rb`.\n\n```ruby\nRSpec.configure do |config|\n  trace = RBS::Trace.new\n\n  config.before(:suite) { trace.enable }\n  config.after(:suite) do\n    trace.disable\n    trace.save_comments\n  end\nend\n```\n\n### Minitest\n\nAdd the following code to `test_helper.rb`.\n\n```ruby\ntrace = RBS::Trace.new\ntrace.enable\n\nMinitest.after_run do\n  trace.disable\n  trace.save_comments\nend\n```\n\n## Tips\n\n### Insert RBS declarations for specific files only\n\n```ruby\nRBS::Trace.new(paths: Dir.glob(\"#{Dir.pwd}/app/models/**/*.rb\"))\n```\n\n### Change the format of embedded comments\n\nYou can change the comment format.\n\n| `comment_format` | embedded comment |\n|---|---|\n| `:rbs_keyword` (default) | `# @rbs () -\u003e void` |\n| `:rbs_colon` | `#: () -\u003e void` |\n\n```ruby\ntrace.save_comments(:rbs_colon)\n```\n\nor\n\n```bash\n$ rbs-trace inline --rb-dir=app --rb-dir=lib --comment-format=rbs_colon\n```\n\n### Save RBS declarations as files\n\n```ruby\ntrace.save_files(out_dir: \"sig/trace/\")\n```\n\n### Specify generics size\n\nBy default, generics are applied to the generated results only in the following classes.\n\n- Array\n- Hash\n- Range\n\nIf any other classes require generics, configure them as follows.\n\n```ruby\ntrace.add_generics_size!(\"CSV::Table\" =\u003e 1, \"ActiveSupport::HashWithIndifferentAccess\" =\u003e 2)\n```\n\n### Parallel testing\n\nIf you are using a parallel testing gem such as [parallel_tests](https://github.com/grosser/parallel_tests) or [flatware](https://github.com/briandunn/flatware), first save the type definitions in RBS files.\n\n```ruby\ntrace.save_files(out_dir: \"tmp/sig-#{ENV[\"TEST_ENV_NUMBER\"]}\")\n```\n\nThen use `rbs-trace merge` to merge multiple RBS files into one.\n\n```bash\n$ rbs-trace merge --sig-dir='tmp/sig-*' \u003e sig/merged.rbs\n```\n\nFinally, insert comments using the merged RBS files.\n\n```bash\n$ rbs-trace inline --rb-dir=app --rb-dir=lib\n```\n\n### Enable debug logging\n\nIf you want to enable debug logging, specify the environment variable `RBS_TRACE_DEBUG`.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo 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).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/sinsoku/rbs-trace. 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/sinsoku/rbs-trace/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the RBS::Trace project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sinsoku/rbs-trace/blob/main/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinsoku%2Frbs-trace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsinsoku%2Frbs-trace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinsoku%2Frbs-trace/lists"}