The project is in a healthy, maintained state
A stub definition provider for Sorbet runtime dependencies
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Project Readme

sorbet-runtime-stub

This gem provides stub definitions for all the T namespace that Sorbet type signatures need for runtime. This is appropriate for people who want nothing to do with sorbet-runtime when their code is being run.

Disclaimer: This gem is being used in our applications but there are some still features missing and it may have some sharp edges.

Installation

Add this line to your application's Gemfile:

gem 'sorbet-runtime-stub'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install sorbet-runtime-stub

Usage

The most critical thing when loading sorbet-runtime-stub is to never overwrite methods defined by sorbet-runtime, since this would cause silent suppression of runtime type checking.

Thus, this gem will never load stub definitions if sorbet-runtime is present as a loadable gem in the application context. This means that on projects that do not use Bundler, this gem will not install stub definitions, if sorbet-runtime is installed as a gem (but it will also not load sorbet-runtime). On projects that use Bundler, this gem will not install stub definitions, if sorbet-runtime exists in the Gemfile for the currently running group.

Thus, if you don't want to load sorbet-runtime in a production environment in a Rails app, you need to use:

if ENV['RAILS_ENV'] == 'production'
  require 'sorbet-runtime-stub'
else
  require 'sorbet-runtime'
end

and add sorbet-runtime to your Gemfile only for development and test groups.

If you are developing a gem that uses Sorbet in development but don't want the runtime typechecking to affect other code, you can conditionally load the runtime stubs at the top of your gem's code:

require 'sorbet-runtime-stub' unless defined?(T)

You can then require the regular sorbet-runtime in your development-only files (e.g. test helpers, Rakefiles).

Missing features

Some feature from sorbet-runtime like T::Enum and T::Struct as still not supported.

Development

After checking out the repo, run bin/setup to install dependencies. 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 tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Shopify/sorbet-runtime-stub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Sorbet::Runtime::Stub project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.