Class: Sorbet::Private::FindGemRBIs
- Inherits:
-
Object
- Object
- Sorbet::Private::FindGemRBIs
- Includes:
- StepInterface
- Defined in:
- lib/find-gem-rbis.rb
Constant Summary collapse
- XDG_CACHE_HOME =
ENV['XDG_CACHE_HOME'] || "#{ENV['HOME']}/.cache"
- RBI_CACHE_DIR =
"#{XDG_CACHE_HOME}/sorbet/gem-rbis/"
- GEM_DIR =
'rbi'
- HEADER =
Sorbet::Private::Serialize.header(false, 'find-gem-rbis')
Class Method Summary collapse
Class Method Details
.main ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/find-gem-rbis.rb', line 31 def self.main FileUtils.mkdir_p(RBI_CACHE_DIR) unless Dir.exist?(RBI_CACHE_DIR) output_file = File.exist?('Gemfile.lock') ? RBI_CACHE_DIR + Digest::MD5.hexdigest(File.read('Gemfile.lock')) : nil return unless output_file gemspecs = Bundler.load.specs.sort_by(&:name) gem_source_paths = T.let([], T::Array[String]) # Tapioca (https://github.com/Shopify/tapioca) does not require gems `rbi/` folders # to be passed to Sorbet as it copies the signatures at RBI generation time. # # To avoid conflicts between RBIs generated with tapioca and the one provided by the # gem, we disable the `rbi/` caching and let Sorbet use the RBIs from `sorbet/rbi/gems`. unless gemspecs.any? { |g| g.name == 'tapioca' } gemspecs.each do |gemspec| gem_source_paths << paths_within_gem_sources(gemspec) end end File.write(output_file, gem_source_paths.compact.join("\n")) end |
.output_file ⇒ Object
54 55 56 |
# File 'lib/find-gem-rbis.rb', line 54 def self.output_file nil end |
.paths_within_gem_sources(gemspec) ⇒ Object
25 26 27 28 |
# File 'lib/find-gem-rbis.rb', line 25 def self.paths_within_gem_sources(gemspec) gem_rbi = "#{gemspec.full_gem_path}/#{GEM_DIR}" gem_rbi if Dir.exist?(gem_rbi) end |