class Dependabot::Bundler::FileUpdater

Public Class Methods

updated_files_regex() click to toggle source
# File lib/dependabot/bundler/file_updater.rb, line 16
def self.updated_files_regex
  [
    /^Gemfile$/,
    /^Gemfile\.lock$/,
    /^gems\.rb$/,
    /^gems\.locked$/,
    /^*\.gemspec$/
  ]
end

Public Instance Methods

updated_dependency_files() click to toggle source

rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/AbcSize

# File lib/dependabot/bundler/file_updater.rb, line 28
def updated_dependency_files
  updated_files = []

  if gemfile && file_changed?(gemfile)
    updated_files <<
      updated_file(
        file: gemfile,
        content: updated_gemfile_content(gemfile)
      )
  end

  if lockfile && dependencies.any?(&:appears_in_lockfile?)
    updated_files <<
      updated_file(file: lockfile, content: updated_lockfile_content)
  end

  top_level_gemspecs.each do |file|
    next unless file_changed?(file)

    updated_files <<
      updated_file(file: file, content: updated_gemspec_content(file))
  end

  evaled_gemfiles.each do |file|
    next unless file_changed?(file)

    updated_files <<
      updated_file(file: file, content: updated_gemfile_content(file))
  end

  check_updated_files(updated_files)

  base_dir = updated_files.first.directory
  vendor_updater.
    updated_vendor_cache_files(base_directory: base_dir).
    each do |file|
    updated_files << file
  end

  updated_files
end

Private Instance Methods

bundler_version() click to toggle source
# File lib/dependabot/bundler/file_updater.rb, line 165
def bundler_version
  @bundler_version ||= Helpers.bundler_version(lockfile)
end
check_required_files() click to toggle source
# File lib/dependabot/bundler/file_updater.rb, line 95
def check_required_files
  file_names = dependency_files.map(&:name)

  raise "A Gemfile must be provided if a lockfile is!" if lockfile && !gemfile

  return if file_names.any? { |name| name.match?(%r{^[^/]*\.gemspec$}) }
  return if gemfile

  raise "A gemspec or Gemfile must be provided!"
end
check_updated_files(updated_files) click to toggle source
# File lib/dependabot/bundler/file_updater.rb, line 106
def check_updated_files(updated_files)
  return if updated_files.reject { |f| dependency_files.include?(f) }.any?

  raise "No files have changed!"
end
evaled_gemfiles() click to toggle source
# File lib/dependabot/bundler/file_updater.rb, line 122
def evaled_gemfiles
  @evaled_gemfiles ||=
    dependency_files.
    reject { |f| f.name.end_with?(".gemspec") }.
    reject { |f| f.name.end_with?(".specification") }.
    reject { |f| f.name.end_with?(".lock") }.
    reject { |f| f.name.end_with?(".ruby-version") }.
    reject { |f| f.name == "Gemfile" }.
    reject { |f| f.name == "gems.rb" }.
    reject { |f| f.name == "gems.locked" }
end
gemfile() click to toggle source
# File lib/dependabot/bundler/file_updater.rb, line 112
def gemfile
  @gemfile ||= get_original_file("Gemfile") ||
               get_original_file("gems.rb")
end
lockfile() click to toggle source
# File lib/dependabot/bundler/file_updater.rb, line 117
def lockfile
  @lockfile ||= get_original_file("Gemfile.lock") ||
                get_original_file("gems.locked")
end
top_level_gemspecs() click to toggle source
# File lib/dependabot/bundler/file_updater.rb, line 159
def top_level_gemspecs
  dependency_files.
    select { |file| file.name.end_with?(".gemspec") }.
    reject(&:support_file?)
end
updated_gemfile_content(file) click to toggle source
# File lib/dependabot/bundler/file_updater.rb, line 134
def updated_gemfile_content(file)
  GemfileUpdater.new(
    dependencies: dependencies,
    gemfile: file
  ).updated_gemfile_content
end
updated_gemspec_content(gemspec) click to toggle source
# File lib/dependabot/bundler/file_updater.rb, line 141
def updated_gemspec_content(gemspec)
  GemspecUpdater.new(
    dependencies: dependencies,
    gemspec: gemspec
  ).updated_gemspec_content
end
updated_lockfile_content() click to toggle source
# File lib/dependabot/bundler/file_updater.rb, line 148
def updated_lockfile_content
  @updated_lockfile_content ||=
    LockfileUpdater.new(
      dependencies: dependencies,
      dependency_files: dependency_files,
      repo_contents_path: repo_contents_path,
      credentials: credentials,
      options: options
    ).updated_lockfile_content
end
vendor_cache_dir() click to toggle source

Dynamically fetch the vendor cache folder from bundler

# File lib/dependabot/bundler/file_updater.rb, line 75
def vendor_cache_dir
  return @vendor_cache_dir if defined?(@vendor_cache_dir)

  @vendor_cache_dir =
    NativeHelpers.run_bundler_subprocess(
      bundler_version: bundler_version,
      function: "vendor_cache_dir",
      args: {
        dir: repo_contents_path
      }
    )
end
vendor_updater() click to toggle source
# File lib/dependabot/bundler/file_updater.rb, line 88
def vendor_updater
  Dependabot::FileUpdaters::VendorUpdater.new(
    repo_contents_path: repo_contents_path,
    vendor_dir: vendor_cache_dir
  )
end