Class: Dependabot::Cargo::FileUpdater::ManifestUpdater

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/cargo/file_updater/manifest_updater.rb

Instance Method Summary collapse

Constructor Details

#initialize(dependencies:, manifest:) ⇒ ManifestUpdater

Returns a new instance of ManifestUpdater.



22
23
24
25
# File 'lib/dependabot/cargo/file_updater/manifest_updater.rb', line 22

def initialize(dependencies:, manifest:)
  @dependencies = T.let(dependencies, T::Array[Dependabot::Dependency])
  @manifest = T.let(manifest, Dependabot::DependencyFile)
end

Instance Method Details

#updated_manifest_contentObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dependabot/cargo/file_updater/manifest_updater.rb', line 28

def updated_manifest_content
  content = manifest.content
  raise "Manifest has no content" if content.nil?

  dependencies
    .select { |dep| requirement_changed?(manifest, dep) }
    .reduce(content.dup) do |current_content, dep|
      updated_content = current_content

      updated_content = update_requirements(
        content: updated_content,
        filename: manifest.name,
        dependency: dep
      )

      updated_content = update_git_pin(
        content: updated_content,
        filename: manifest.name,
        dependency: dep
      )

      raise "Expected content to change!" if current_content == updated_content

      updated_content
    end
end