class Gem::RequestSet::Lockfile

Parses a gem.deps.rb.lock file and constructs a LockSet containing the dependencies found inside. If the lock file is missing no LockSet is constructed.

Attributes

platforms[R]

The platforms for this Lockfile

Public Class Methods

build(request_set, gem_deps_file, dependencies = nil) click to toggle source

Creates a new Lockfile for the given request_set and gem_deps_file location.

# File lib/rubygems/request_set/lockfile.rb, line 44
def self.build(request_set, gem_deps_file, dependencies = nil)
  request_set.resolve
  dependencies ||= requests_to_deps request_set.sorted_requests
  new request_set, gem_deps_file, dependencies
end
new(request_set, gem_deps_file, dependencies) click to toggle source
# File lib/rubygems/request_set/lockfile.rb, line 74
def initialize(request_set, gem_deps_file, dependencies)
  @set           = request_set
  @dependencies  = dependencies
  @gem_deps_file = File.expand_path(gem_deps_file)
  @gem_deps_dir  = File.dirname(@gem_deps_file)

  @gem_deps_file.untaint unless gem_deps_file.tainted?

  @platforms      = []
end

Public Instance Methods

add_GIT(out, git_requests) click to toggle source
# File lib/rubygems/request_set/lockfile.rb, line 125
  def add_GIT(out, git_requests)
    return if git_requests.empty?

    by_repository_revision = git_requests.group_by do |request|
      source = request.spec.source
      [source.repository, source.rev_parse]
    end

    by_repository_revision.each do |(repository, revision), requests|
      out << "GIT"
      out << "  remote: #{repository}"
      out << "  revision: #{revision}"
      out << "  specs:"

      requests.sort_by { |request| request.name }.each do |request|
        out << "    #{request.name} (#{request.version})"

        dependencies = request.spec.dependencies.sort_by { |dep| dep.name }
        dependencies.each do |dep|
          out << "      #{dep.name}#{dep.requirement.for_lockfile}"
        end
      end
      out << nil
    end
  end

  def relative_path_from(dest, base) # :nodoc:
    dest = File.expand_path(dest)
    base = File.expand_path(base)

    if dest.index(base) == 0
      offset = dest[base.size+1..-1]

      return '.' unless offset

      offset
    else
      dest
    end
  end

  def add_PATH(out, path_requests) # :nodoc:
    return if path_requests.empty?

    out << "PATH"
    path_requests.each do |request|
      directory = File.expand_path(request.spec.source.uri)

      out << "  remote: #{relative_path_from directory, @gem_deps_dir}"
      out << "  specs:"
      out << "    #{request.name} (#{request.version})"
    end

    out << nil
  end

  def add_PLATFORMS(out) # :nodoc:
    out << "PLATFORMS"

    platforms = requests.map { |request| request.spec.platform }.uniq

    platforms = platforms.sort_by { |platform| platform.to_s }

    platforms.each do |platform|
      out << "  #{platform}"
    end

    out << nil
  end

  def spec_groups
    requests.group_by { |request| request.spec.class }
  end

  ##
  # The contents of the lock file.

  def to_s
    out = []

    groups = spec_groups

    add_PATH out, groups.delete(Gem::Resolver::VendorSpecification) { [] }

    add_GIT out, groups.delete(Gem::Resolver::GitSpecification) { [] }

    add_GEM out, groups

    add_PLATFORMS out

    add_DEPENDENCIES out

    out.join "\n"
  end

  ##
  # Writes the lock file alongside the gem dependencies file

  def write
    content = to_s

    File.open "#{@gem_deps_file}.lock", 'w' do |io|
      io.write content
    end
  end

  private

  def requests
    @set.sorted_requests
  end
end

require
requests() click to toggle source
# File lib/rubygems/request_set/lockfile.rb, line 233
def requests
  @set.sorted_requests
end
spec_groups() click to toggle source
# File lib/rubygems/request_set/lockfile.rb, line 195
def spec_groups
  requests.group_by { |request| request.spec.class }
end
to_s() click to toggle source

The contents of the lock file.

# File lib/rubygems/request_set/lockfile.rb, line 202
def to_s
  out = []

  groups = spec_groups

  add_PATH out, groups.delete(Gem::Resolver::VendorSpecification) { [] }

  add_GIT out, groups.delete(Gem::Resolver::GitSpecification) { [] }

  add_GEM out, groups

  add_PLATFORMS out

  add_DEPENDENCIES out

  out.join "\n"
end
write() click to toggle source

Writes the lock file alongside the gem dependencies file

# File lib/rubygems/request_set/lockfile.rb, line 223
def write
  content = to_s

  File.open "#{@gem_deps_file}.lock", 'w' do |io|
    io.write content
  end
end