Class: Dependabot::Cargo::UpdateChecker::RequirementsUpdater

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

Defined Under Namespace

Classes: UnfixableRequirement

Constant Summary collapse

VERSION_REGEX =
/[0-9]+(?:\.[A-Za-z0-9\-*]+)*/
ALLOWED_UPDATE_STRATEGIES =
T.let(
  [
    RequirementsUpdateStrategy::LockfileOnly,
    RequirementsUpdateStrategy::BumpVersions,
    RequirementsUpdateStrategy::BumpVersionsIfNecessary
  ].freeze,
  T::Array[Dependabot::RequirementsUpdateStrategy]
)

Instance Method Summary collapse

Constructor Details

#initialize(requirements:, updated_source:, update_strategy:, target_version:) ⇒ RequirementsUpdater

Returns a new instance of RequirementsUpdater.



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

def initialize(requirements:, updated_source:, update_strategy:,
               target_version:)
  @requirements = requirements
  @updated_source = updated_source
  @update_strategy = update_strategy

  check_update_strategy

  return unless target_version && version_class.correct?(target_version)

  @target_version = version_class.new(target_version)
end

Instance Method Details

#updated_requirementsObject



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

def updated_requirements
  return requirements if update_strategy.lockfile_only?

  # 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|
    req = req.merge(source: updated_source)
    next req unless target_version
    next req if req[:requirement].nil?

    # TODO: Add a RequirementsUpdateStrategy::WidenRanges options
    if update_strategy == RequirementsUpdateStrategy::BumpVersionsIfNecessary
      update_version_requirement_if_needed(req)
    else
      update_version_requirement(req)
    end
  end
end