class RBS::Collection::Config::LockfileGenerator

Attributes

config[R]
definition[R]
existing_lockfile[R]
gem_hash[R]
lockfile[R]

Public Class Methods

generate(config:, definition:, with_lockfile: true) click to toggle source
# File rbs-3.1.0/lib/rbs/collection/config/lockfile_generator.rb, line 25
def self.generate(config:, definition:, with_lockfile: true)
  generator = new(config: config, definition: definition, with_lockfile: with_lockfile)
  generator.generate
  generator.lockfile
end
new(config:, definition:, with_lockfile:) click to toggle source
# File rbs-3.1.0/lib/rbs/collection/config/lockfile_generator.rb, line 31
def initialize(config:, definition:, with_lockfile:)
  @config = config

  lockfile_path = Config.to_lockfile_path(config.config_path)
  lockfile_dir = lockfile_path.parent

  @lockfile = Lockfile.new(
    lockfile_path: lockfile_path,
    path: config.repo_path_data,
    gemfile_lock_path: definition.lockfile.relative_path_from(lockfile_dir)
  )
  config.sources.each do |source|
    case source
    when Sources::Git
      lockfile.sources[source.name] = source
    end
  end

  if with_lockfile && lockfile_path.file?
    @existing_lockfile = Lockfile.from_lockfile(lockfile_path: lockfile_path, data: YAML.load_file(lockfile_path.to_s))
    validate_gemfile_lock_path!(lock: @existing_lockfile, gemfile_lock_path: definition.lockfile)
  end

  @definition = definition
  @gem_hash = definition.locked_gems.specs.each.with_object({}) do |spec, hash|  #$ Hash[String, Bundler::LazySpecification]
    hash[spec.name] = spec
  end
end

Public Instance Methods

generate() click to toggle source
# File rbs-3.1.0/lib/rbs/collection/config/lockfile_generator.rb, line 60
def generate
  ignored_gems = config.gems.select {|gem| gem["ignore"] }.map {|gem| gem["name"] }.to_set

  config.gems.each do |gem|
    if Sources::Stdlib.instance.has?(gem["name"], nil) || gem.dig("source", "type") == "stdlib"
      unless ignored_gems.include?(gem["name"])
        assign_stdlib(name: gem["name"], from_gem: nil)
      end
    else
      assign_gem(name: gem["name"], version: gem["version"], ignored_gems: ignored_gems, src_data: gem["source"])
    end
  end

  definition.dependencies.each do |dep|
    if dep.autorequire && dep.autorequire.empty?
      next
    end

    if spec = gem_hash[dep.name]
      assign_gem(name: dep.name, version: spec.version, ignored_gems: ignored_gems, src_data: nil, skip: dep.source.is_a?(Bundler::Source::Gemspec))
    end
  end

  lockfile.lockfile_path.write(YAML.dump(lockfile.to_lockfile))
end