class Dependabot::Bundler::FileParser::FilePreparer

Attributes

dependency_files[R]

Public Class Methods

new(dependency_files:) click to toggle source
# File lib/dependabot/bundler/file_parser/file_preparer.rb, line 11
def initialize(dependency_files:)
  @dependency_files = dependency_files
end

Public Instance Methods

prepared_dependency_files() click to toggle source
# File lib/dependabot/bundler/file_parser/file_preparer.rb, line 15
def prepared_dependency_files
  files = []

  gemspecs.compact.each do |file|
    files << DependencyFile.new(
      name: file.name,
      content: sanitize_gemspec_content(file.content),
      directory: file.directory,
      support_file: file.support_file?
    )
  end

  files += [
    gemfile,
    *evaled_gemfiles,
    lockfile,
    ruby_version_file,
    *imported_ruby_files,
    *specification_files
  ].compact
end

Private Instance Methods

evaled_gemfiles() click to toggle source
# File lib/dependabot/bundler/file_parser/file_preparer.rb, line 46
def 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_parser/file_preparer.rb, line 41
def gemfile
  dependency_files.find { |f| f.name == "Gemfile" } ||
    dependency_files.find { |f| f.name == "gems.rb" }
end
gemspecs() click to toggle source
# File lib/dependabot/bundler/file_parser/file_preparer.rb, line 66
def gemspecs
  dependency_files.select { |f| f.name.end_with?(".gemspec") }
end
imported_ruby_files() click to toggle source
# File lib/dependabot/bundler/file_parser/file_preparer.rb, line 74
def imported_ruby_files
  dependency_files.
    select { |f| f.name.end_with?(".rb") }.
    reject { |f| f.name == "gems.rb" }
end
lockfile() click to toggle source
# File lib/dependabot/bundler/file_parser/file_preparer.rb, line 61
def lockfile
  dependency_files.find { |f| f.name == "Gemfile.lock" } ||
    dependency_files.find { |f| f.name == "gems.locked" }
end
ruby_version_file() click to toggle source
# File lib/dependabot/bundler/file_parser/file_preparer.rb, line 70
def ruby_version_file
  dependency_files.find { |f| f.name == ".ruby-version" }
end
sanitize_gemspec_content(gemspec_content) click to toggle source
# File lib/dependabot/bundler/file_parser/file_preparer.rb, line 80
def sanitize_gemspec_content(gemspec_content)
  # No need to set the version correctly - this is just an update
  # check so we're not going to persist any changes to the lockfile.
  FileUpdater::GemspecSanitizer.
    new(replacement_version: "0.0.1").
    rewrite(gemspec_content)
end
specification_files() click to toggle source
# File lib/dependabot/bundler/file_parser/file_preparer.rb, line 57
def specification_files
  dependency_files.select { |f| f.name.end_with?(".specification") }
end