Orthoses is a framework for RBS generation. The Rack architecture keeps your code organized and extensible.
- You can choose which middleware to use.
- You can write your own middleware to use.
- You can publish your middleware and share it with the world.
https://gist.github.com/ksss/00592da24f28774bf8fc5db08331666e
Install the gem and add to the application's Gemfile by executing:
$ bundle add orthoses
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install orthoses
For example, You can write script in Rakefile.
require 'orthoses'
namespace :rbs do
desc "build RBS to sig/orthoses"
task :build do
Orthoses::Builder.new do
use Orthoses::CreateFileByName,
depth: 1,
to: "sig/orthoses",
rmtree: true,
header: "# !!! GENERATED CODE !!!"
use Orthoses::Filter do |name, _content|
path, _lineno = Object.const_source_location(name)
return false unless path
%r{app/models}.match?(path)
end
use YourCustom::Middleware
use Orthoses::Mixin
use Orthoses::Constant
use Orthoses::Walk,
root: "Foo"
run -> {
# load library or application
}
end.call
end
end
Then, you can see the result files under sig/orthoses
.
Orthoses::Utils
is a collection of useful methods.
Yield const by recursive.
Checks if the const name is already defined.
Checks if the class name is already defined.
Fetch cached RBS::Environment
.
Convert Ruby object to RBS string.
Get true module name by Module.instance_method(:name).bind(mod).call
.
Add constant signature to class/module. Signatures are predicted from constant values.
Add attr
, attr_accessor
, attr_reader
and attr_writer
to output RBS.
All type set untyped
.
Add module include/extend/prepend definition.
Add module/class by ObjectSpace.each_object(Module)
Separate directories for each module name and output RBS files.
Filter stored value by name and content.
Debug pring current stored values
Load RBS from paths
.
And loaded RBS will write to output.
Load class/module recersive from root
constant.
If set String to root
, It get constant after loading.
Get the current store in the block as an argument. This is very useful for middleware development and debugging.
If a class is defined using the DelegateClass
method
RBS is automatically generated as inherited.
.rb
class Tempfile < DelegateClass(File)
end
.rbs
class Tempfile < File
end
Write output RBS to io
option object.
io
should be able to call #write
method.
This is useful when you want to combine outputs into a single output.
Run rbs prototype rb
command process to paths
option files.
content_filter
option could filter with content decl.
mixin_filter
option could filter with mixin(include, extend, prepend) decl.
Run rbs prototype runtime
command process with patterns
option string.
Force load const defined by autoload
.
Sort signatures by class/module.
Trace the argument and return value objects when the method is actually called and determine the type.
Completes undefined class/module names. If it is unknown whether it is a class or a module, it is defined as an empty module, and if it is a superclass, it is defined as an empty class.
You can specify that the specified RBS should not be intentionally generated. This is useful when you want to exclude handwritten RBS.
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 the created tag, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/ksss/orthoses. 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 Orthoses project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
- Share middleware sets for commonly used use cases.
- For library.
- For application.