
Security News
CISA’s 2025 SBOM Guidance Adds Hashes, Licenses, Tool Metadata, and Context
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
RBS::Trace automatically collects argument and return types and saves RBS type declarations as RBS files or comments.
Install the gem and add to the application's Gemfile by executing:
$ bundle add rbs-trace
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install rbs-trace
For example, suppose you have the following class:
class User
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
def full_name
"#{@first_name} #{@last_name}"
end
def say_hello
puts "hi, #{full_name}."
end
end
Call target methods within the enable
method block, and call the save_comments
method.
trace = RBS::Trace.new
# Collects the types of methods called in the block.
trace.enable do
user = User.new("Nanoha", "Takamachi")
user.say_hello
end
# Save RBS type declarations as embedded comments
trace.save_comments
Automatically insert comments into the file.
class User
# @rbs (String, String) -> void
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
# @rbs () -> String
def full_name
"#{@first_name} #{@last_name}"
end
# @rbs () -> void
def say_hello
puts "hi, #{full_name}."
end
end
Add the following code to spec/support/rbs_trace.rb
.
RSpec.configure do |config|
trace = RBS::Trace.new
config.before(:suite) { trace.enable }
config.after(:suite) do
trace.disable
trace.save_comments
end
end
Add the following code to test_helper.rb
.
trace = RBS::Trace.new
trace.enable
Minitest.after_run do
trace.disable
trace.save_comments
end
RBS::Trace.new(paths: Dir.glob("#{Dir.pwd}/app/models/**/*.rb"))
You can change the comment format.
comment_format | embedded comment |
---|---|
:rbs_keyword (default) | # @rbs () -> void |
:rbs_colon | #: () -> void |
trace.save_comments(:rbs_colon)
or
$ rbs-trace inline --rb-dir=app --rb-dir=lib --comment-format=rbs_colon
trace.save_files(out_dir: "sig/trace/")
If you are using a parallel testing gem such as parallel_tests or flatware, first save the type definitions in RBS files.
trace.save_files(out_dir: "tmp/sig-#{ENV["TEST_ENV_NUMBER"]}")
Then use rbs-trace merge
to merge multiple RBS files into one.
$ rbs-trace merge --sig-dir='tmp/sig-*' > sig/merged.rbs
Finally, insert comments using the merged RBS files.
$ rbs-trace inline --rb-dir=app --rb-dir=lib
If you want to enable debug logging, specify the environment variable RBS_TRACE_DEBUG
.
After 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.
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.
Bug 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.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the RBS::Trace project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that rbs-trace demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.