class RBS::Collection::Sources::Local
属性
full_path[R]
path[R]
公共类方法
new(path:, base_directory:) 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/sources/local.rb, line 11 def initialize(path:, base_directory:) # TODO: resolve relative path from dir of rbs_collection.yaml @path = Pathname(path) @full_path = base_directory / path end
公共实例方法
has?(name, version) 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/sources/local.rb, line 17 def has?(name, version) if version @full_path.join(name, version).directory? else not versions(name).empty? end end
install(dest:, name:, version:, stdout:) 点击切换源代码
创建符号链接而不是复制文件来引用 @path 中的文件。通过避免复制 RBS
文件,用户在更新 RBS
文件时不需要重新运行 'rbs collection install'。
# File rbs-3.8.0/lib/rbs/collection/sources/local.rb, line 32 def install(dest:, name:, version:, stdout:) from = @full_path.join(name, version) gem_dir = dest.join(name, version) colored_io = CLI::ColoredIO.new(stdout: stdout) case when gem_dir.symlink? && gem_dir.readlink == from colored_io.puts "Using #{name}:#{version} (#{from})" when gem_dir.symlink? prev = gem_dir.readlink gem_dir.unlink _install(from, dest.join(name, version)) colored_io.puts_green("Updating #{name}:#{version} to #{from} from #{prev}") when gem_dir.directory? # TODO: Show version of git source FileUtils.remove_entry_secure(gem_dir.to_s) _install(from, dest.join(name, version)) colored_io.puts_green("Updating #{name}:#{version} from git source") when !gem_dir.exist? _install(from, dest.join(name, version)) colored_io.puts_green("Installing #{name}:#{version} (#{from})") else raise end end
manifest_of(name, version) 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/sources/local.rb, line 64 def manifest_of(name, version) gem_dir = @full_path.join(name, version) raise unless gem_dir.exist? manifest_path = gem_dir.join('manifest.yaml') YAML.safe_load(manifest_path.read) if manifest_path.exist? end
to_lockfile() 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/sources/local.rb, line 72 def to_lockfile { 'type' => 'local', 'path' => @path.to_s, } end
versions(name) 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/sources/local.rb, line 25 def versions(name) @full_path.join(name).glob('*/').map { |path| path.basename.to_s } end
私有实例方法
_install(src, dst) 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/sources/local.rb, line 59 def _install(src, dst) dst.dirname.mkpath File.symlink(src, dst) end