class RBS::Collection::Config

此类表示配置文件。

常量

PATH

属性

config_path[R]
data[R]

公共类方法

find_config_path() 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/config.rb, line 21
def self.find_config_path
  current = Pathname.pwd

  loop do
    config_path = current.join(PATH)
    return config_path if config_path.exist?
    current = current.join('..')
    return nil if current.root?
  end
end
from_path(path) 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/config.rb, line 41
def self.from_path(path)
  new(YAML.load(path.read), config_path: path)
end
generate_lockfile(config_path:, definition:, with_lockfile: true) 点击切换源代码

从 Gemfile.lock 生成一个 rbs 锁文件到 ‘config_path’。如果 `with_lockfile` 为 true,它会尊重现有的 rbs 锁文件。

# File rbs-3.8.0/lib/rbs/collection/config.rb, line 34
def self.generate_lockfile(config_path:, definition:, with_lockfile: true)
  config = from_path(config_path)
  lockfile = LockfileGenerator.generate(config: config, definition: definition, with_lockfile: with_lockfile)

  [config, lockfile]
end
new(data, config_path:) 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/config.rb, line 49
def initialize(data, config_path:)
  @data = data
  @config_path = config_path
end
to_lockfile_path(config_path) 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/config.rb, line 45
def self.to_lockfile_path(config_path)
  config_path.sub_ext('.lock' + config_path.extname)
end

公共实例方法

gem(gem_name) 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/config.rb, line 54
def gem(gem_name)
  gems.find { |gem| gem['name'] == gem_name }
end
gems() 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/config.rb, line 74
def gems
  @data['gems'] ||= (
    [] #: Array[gem_entry]
  )
end
repo_path() 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/config.rb, line 58
def repo_path
  @config_path.dirname.join repo_path_data
end
repo_path_data() 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/config.rb, line 62
def repo_path_data
  Pathname(@data["path"])
end
sources() 点击切换源代码
# File rbs-3.8.0/lib/rbs/collection/config.rb, line 66
def sources
  @sources ||= [
    Sources::Rubygems.instance,
    *@data['sources'].map { |c| Sources.from_config_entry(c, base_directory: @config_path.dirname) },
    Sources::Stdlib.instance
  ]
end