bin/postprocess.rb in rbs_rails-0.3.0 vs bin/postprocess.rb in rbs_rails-0.4.0
- old
+ new
@@ -1,24 +1,29 @@
#!ruby
# TODO: Expose me to user
+require 'bundler/inline'
+
+gemfile do
+ source 'https://rubygems.org'
+ gem 'rbs', '>= 0.16'
+end
+
require 'rbs'
require 'rbs/cli'
require 'optparse'
def env(options:)
- loader = RBS::EnvironmentLoader.new()
- options.setup(loader)
+ loader = options.loader
RBS::Environment.from_loader(loader).resolve_type_names
end
def parse_option(argv)
opt = OptionParser.new
options = RBS::CLI::LibraryOptions.new
- cli = RBS::CLI.new(stdout: nil, stderr: nil)
- cli.library_parse(opt, options: options)
+ options.setup_library_options(opt)
return opt.parse(argv), options
end
class FileMatcher
@@ -77,12 +82,14 @@
def may_eql_member?(a, b)
a.name.to_s.split('::').last == b.name.to_s.split('::').last
end
-def update!(update_targets:)
+def update!(update_targets:, only:)
update_targets.group_by { |decl, _concern| decl.location.name }.each do |fname, target_decls|
+ next unless only.match?(fname)
+
tree = RBS::Parser.parse_signature(File.read(fname))
target_decls.each do |target_decl, concern|
catch(:break) do
tree.each do |node|
each_decl_descendant(decl: node) do |decl:, path:|
@@ -107,10 +114,12 @@
targets, options = parse_option(argv)
env = env(options: options)
builder = RBS::DefinitionBuilder.new(env: env)
matcher = FileMatcher.new(targets: targets)
+ only = ENV['ONLY']&.then { Regexp.new(_1) } || //
+
update_targets = []
env.class_decls.each do |_name, entry|
entry.decls.each do |d|
decl = d.decl
@@ -120,9 +129,9 @@
process(decl, env: env, builder: builder, update_targets: update_targets)
end
end
- update!(update_targets: update_targets)
+ update!(update_targets: update_targets, only: only)
end
run(ARGV)