Class: Dependabot::Gradle::FileUpdater::DependencySetUpdater

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

Instance Method Summary collapse

Constructor Details

#initialize(dependency_files:) ⇒ DependencySetUpdater

Returns a new instance of DependencySetUpdater.



16
17
18
# File 'lib/dependabot/gradle/file_updater/dependency_set_updater.rb', line 16

def initialize(dependency_files:)
  @dependency_files = dependency_files
end

Instance Method Details

#update_files_for_dep_set_change(dependency_set:, buildfile:, previous_requirement:, updated_requirement:) ⇒ Object



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

def update_files_for_dep_set_change(dependency_set:,
                                    buildfile:,
                                    previous_requirement:,
                                    updated_requirement:)
  declaration_string =
    original_declaration_string(dependency_set, buildfile)

  return dependency_files unless declaration_string

  updated_content = T.must(buildfile.content).sub(
    declaration_string,
    declaration_string.sub(
      previous_requirement,
      updated_requirement
    )
  )

  updated_files = dependency_files.dup
  updated_files[T.must(updated_files.index(buildfile))] =
    update_file(file: buildfile, content: updated_content)

  updated_files
end