Class: Dependabot::UpdateCheckers::Rust::Cargo::RequirementsUpdater

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/update_checkers/rust/cargo/requirements_updater.rb

Defined Under Namespace

Classes: UnfixableRequirement

Constant Summary collapse

VERSION_REGEX =
/[0-9]+(?:\.[A-Za-z0-9\-*]+)*/.freeze
ALLOWED_UPDATE_STRATEGIES =
i(bump_versions bump_versions_if_necessary).freeze

Instance Method Summary collapse

Constructor Details

#initialize(requirements:, updated_source:, update_strategy:, library:, latest_version:, latest_resolvable_version:) ⇒ RequirementsUpdater



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

def initialize(requirements:, updated_source:, update_strategy:,
               library:, latest_version:, latest_resolvable_version:)
  @requirements = requirements
  @updated_source = updated_source
  @update_strategy = update_strategy
  @library = library

  check_update_strategy

  if latest_version && version_class.correct?(latest_version)
    @latest_version = version_class.new(latest_version)
  end

  return unless latest_resolvable_version
  return unless version_class.correct?(latest_resolvable_version)

  @latest_resolvable_version =
    version_class.new(latest_resolvable_version)
end

Instance Method Details

#updated_requirementsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dependabot/update_checkers/rust/cargo/requirements_updater.rb', line 44

def updated_requirements
  # 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 latest_resolvable_version
    next req if req[:requirement].nil?

    # TODO: Add a widen_ranges options
    if update_strategy == :bump_versions_if_necessary
      update_version_requirement_if_needed(req)
    else
      update_version_requirement(req)
    end
  end
end