123456789_123456789_123456789_123456789_123456789_

Class: RBS::Vendorer

Relationships & Source Files
Inherits: Object
Defined in: lib/rbs/vendorer.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(vendor_dir:, loader:) ⇒ Vendorer

[ GitHub ]

  
# File 'lib/rbs/vendorer.rb', line 8

def initialize(vendor_dir:, loader:)
  @vendor_dir = vendor_dir
  @loader = loader
end

Instance Attribute Details

#loader (readonly)

[ GitHub ]

  
# File 'lib/rbs/vendorer.rb', line 6

attr_reader :loader

#vendor_dir (readonly)

[ GitHub ]

  
# File 'lib/rbs/vendorer.rb', line 5

attr_reader :vendor_dir

Instance Method Details

#clean!

[ GitHub ]

  
# File 'lib/rbs/vendorer.rb', line 21

def clean!
  ensure_dir do
    RBS.logger.info "Cleaning vendor root: #{vendor_dir}..."
    vendor_dir.rmtree
  end
end

#copy!

[ GitHub ]

  
# File 'lib/rbs/vendorer.rb', line 28

def copy!
  # @type var paths: Set[[Pathname, Pathname]]
  paths = Set[]

  if core_root = loader.core_root
    RBS.logger.info "Vendoring core RBSs in #{vendor_dir + "core"}..."
    FileFinder.each_file(core_root, immediate: false, skip_hidden: true) do |file_path|
      paths << [file_path, Pathname("core") + file_path.relative_path_from(core_root)]
    end
  end

  loader.libs.each do |lib|
    case
    when (spec, path = EnvironmentLoader.gem_sig_path(lib.name, lib.version))
      dest_dir = Pathname("#{lib.name}-#{spec.version}")

      RBS.logger.info "Vendoring #{lib.name}(#{spec.version}) RBSs in #{vendor_dir + dest_dir}..."

      FileFinder.each_file(path, skip_hidden: true, immediate: false) do |file_path|
        paths << [file_path, dest_dir + file_path.relative_path_from(path)]
      end

    when (rbs, path = loader.repository.lookup_path(lib.name, lib.version))
      dest_dir = Pathname("#{rbs.name}-#{path.version}")

      RBS.logger.info "Vendoring #{lib.name}(#{path.version}) RBSs in #{vendor_dir + dest_dir}..."

      FileFinder.each_file(path.path, skip_hidden: true, immediate: false) do |file_path|
        paths << [file_path, dest_dir + file_path.relative_path_from(path.path)]
      end
    else
      RBS.logger.error "Couldn't find RBSs for #{lib.name} (#{lib.version}); skipping..."
    end
  end

  paths.each do |from, to|
    dest = vendor_dir + to
    dest.parent.mkpath unless dest.parent.directory?

    FileUtils.copy_file(from.to_s, dest.to_s)
  end
end

#ensure_dir

[ GitHub ]

  
# File 'lib/rbs/vendorer.rb', line 13

def ensure_dir
  unless vendor_dir.directory?
    vendor_dir.mkpath
  end

  yield
end