Skip to content

Commit

Permalink
Filter versions during test
Browse files Browse the repository at this point in the history
  • Loading branch information
KaanOzkan committed Sep 27, 2024
1 parent 077e9ab commit cf6565b
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions gem/lib/rbi-central/static/context.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# typed: strict
# frozen_string_literal: true

require "debug"
module RBICentral
module Static
class Context < RBICentral::Context
Expand Down Expand Up @@ -28,16 +29,17 @@ def run!
errors = super
return errors if errors.any?

filtered_rbi = filter_versions_from_annotation(@gem.name, @annotations_file)

# Write the filtered annotation to the context folder
write!(annotations_file, filtered_rbi)

res = bundle_exec("tapioca gem --no-doc --post requires.rb")
unless res.status
errors << Error.new(T.must(res.err).lstrip)
return errors
end

# Copy annotations file inside the context so path look relative
FileUtils.mkdir_p("#{absolute_path}/rbi/annotations")
FileUtils.cp(@annotations_file, "#{absolute_path}/#{@annotations_file}")

res = bundle_exec("tapioca check-shims --no-payload " \
"--gem-rbi-dir=sorbet/rbi/gems " \
"--shim-rbi-dir=rbi/annotations " \
Expand Down Expand Up @@ -78,6 +80,17 @@ def add_require(name)
require "#{name}"
RB
end

private

sig { params(gem_name: String, annotations_file: String).returns(String) }
def filter_versions_from_annotation(gem_name, annotations_file)
gem_version = ::Gem::Version.new(gem_version_from_gemfile_lock(gem_name))
rbi = RBI::Parser.parse_file(annotations_file)
rbi.filter_versions!(gem_version)

rbi.string
end
end
end
end

0 comments on commit cf6565b

Please sign in to comment.