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

Inherits:
Object
  • Object
show all
Extended by:
T::Generic, T::Sig
Includes:
RequirementsUpdater::Base
Defined in:
lib/dependabot/gradle/update_checker/requirements_updater.rb

Constant Summary collapse

Version =
type_member { { fixed: Dependabot::Gradle::Version } }
Requirement =
type_member { { fixed: Dependabot::Gradle::Requirement } }

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RequirementsUpdater.



37
38
39
40
41
42
43
44
45
# File 'lib/dependabot/gradle/update_checker/requirements_updater.rb', line 37

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 = T.let(version_class.new(latest_version), Version)
end

Instance Method Details

#updated_requirementsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/dependabot/gradle/update_checker/requirements_updater.rb', line 48

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