123456789_123456789_123456789_123456789_123456789_

Class: Bundler::LockfileGenerator

Relationships & Source Files
Inherits: Object
Defined in: lib/bundler/lockfile_generator.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(definition) ⇒ LockfileGenerator

This method is for internal use only.
[ GitHub ]

  
# File 'lib/bundler/lockfile_generator.rb', line 9

def initialize(definition)
  @definition = definition
  @out = String.new
end

Class Method Details

.generate(definition)

[ GitHub ]

  
# File 'lib/bundler/lockfile_generator.rb', line 14

def self.generate(definition)
  new(definition).generate!
end

Instance Attribute Details

#definition (readonly)

[ GitHub ]

  
# File 'lib/bundler/lockfile_generator.rb', line 5

attr_reader :definition

#out (readonly)

[ GitHub ]

  
# File 'lib/bundler/lockfile_generator.rb', line 6

attr_reader :out

Instance Method Details

#add_bundled_with (private)

[ GitHub ]

  
# File 'lib/bundler/lockfile_generator.rb', line 82

def add_bundled_with
  add_section("BUNDLED WITH", definition.bundler_version_to_lock.to_s)
end

#add_checksums (private)

[ GitHub ]

  
# File 'lib/bundler/lockfile_generator.rb', line 69

def add_checksums
  return unless definition.locked_checksums
  checksums = definition.resolve.map do |spec|
    spec.source.checksum_store.to_lock(spec)
  end
  add_section("CHECKSUMS", checksums)
end

#add_dependencies (private)

[ GitHub ]

  
# File 'lib/bundler/lockfile_generator.rb', line 58

def add_dependencies
  out << "\nDEPENDENCIES\n"

  handled = []
  definition.dependencies.sort_by(&:to_s).each do |dep|
    next if handled.include?(dep.name)
    out << dep.to_lock << "\n"
    handled << dep.name
  end
end

#add_locked_ruby_version (private)

[ GitHub ]

  
# File 'lib/bundler/lockfile_generator.rb', line 77

def add_locked_ruby_version
  return unless locked_ruby_version = definition.locked_ruby_version
  add_section("RUBY VERSION", locked_ruby_version.to_s)
end

#add_platforms (private)

[ GitHub ]

  
# File 'lib/bundler/lockfile_generator.rb', line 54

def add_platforms
  add_section("PLATFORMS", definition.platforms)
end

#add_section(name, value) (private)

[ GitHub ]

  
# File 'lib/bundler/lockfile_generator.rb', line 86

def add_section(name, value)
  out << "\n#{name}\n"
  case value
  when Array
    value.map(&:to_s).sort.each do |val|
      out << "  #{val}\n"
    end
  when Hash
    value.to_a.sort_by {|k, _| k.to_s }.each do |key, val|
      out << "  #{key}: #{val}\n"
    end
  when String
    out << "   #{value}\n"
  else
    raise ArgumentError, "#{value.inspect} can't be serialized in a lockfile"
  end
end

#add_sources (private)

[ GitHub ]

  
# File 'lib/bundler/lockfile_generator.rb', line 31

def add_sources
  definition.sources.lock_sources.each_with_index do |source, idx|
    out << "\n" unless idx.zero?

    # Add the source header
    out << source.to_lock

    # Find all specs for this source
    specs = definition.resolve.select {|s| source.can_lock?(s) }
    add_specs(specs)
  end
end

#add_specs(specs) (private)

[ GitHub ]

  
# File 'lib/bundler/lockfile_generator.rb', line 44

def add_specs(specs)
  # This needs to be sorted by full name so that
  # gems with the same name, but different platform
  # are ordered consistently
  specs.sort_by(&:full_name).each do |spec|
    next if spec.name == "bundler"
    out << spec.to_lock
  end
end

#generate!

[ GitHub ]

  
# File 'lib/bundler/lockfile_generator.rb', line 18

def generate!
  add_sources
  add_platforms
  add_dependencies
  add_checksums
  add_locked_ruby_version
  add_bundled_with

  out
end