Class: Dependabot::Gradle::UpdateChecker::RequirementsUpdater

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/gradle/update_checker/requirements_updater.rb

Instance Method Summary collapse

Constructor Details

#initialize(requirements:, latest_version:, source_url:, properties_to_update:) ⇒ RequirementsUpdater

Returns a new instance of RequirementsUpdater.



16
17
18
19
20
21
22
23
24
# File 'lib/dependabot/gradle/update_checker/requirements_updater.rb', line 16

def initialize(requirements:, latest_version:, source_url:,
               properties_to_update:)
  @requirements = requirements
  @source_url = source_url
  @properties_to_update = properties_to_update
  return unless latest_version

  @latest_version = version_class.new(latest_version)
end

Instance Method Details

#updated_requirementsObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dependabot/gradle/update_checker/requirements_updater.rb', line 26

def updated_requirements
  return requirements unless latest_version

  # NOTE: Order is important here. The FileUpdater needs the updated
  # requirement at index `i` to correspond to the previous requirement
  # at the same index.
  requirements.map do |req|
    next req if req.fetch(:requirement).nil?
    next req if req.fetch(:requirement).include?(",")

    property_name = req.dig(:metadata, :property_name)
    next req if property_name && !properties_to_update.include?(property_name)

    new_req = update_requirement(req[:requirement])
    req.merge(requirement: new_req, source: updated_source)
  end
end