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.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dependabot/gradle/update_checker/requirements_updater.rb', line 39

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)
  @is_distribution = T.let(Distributions.distribution_requirements?(requirements), T::Boolean)
end

Instance Method Details

#updated_requirementsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/dependabot/gradle/update_checker/requirements_updater.rb', line 55

def updated_requirements
  return requirements unless latest_version
  return updated_distribution_requirements if @is_distribution

  # 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