Class: Dependabot::Requirement

Inherits:
Gem::Requirement
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/dependabot/requirement.rb

Constant Summary collapse

MINIMUM_OPERATORS =

Constants for operator groups

%w(>= > ~>).freeze
MAXIMUM_OPERATORS =
%w(<= < ~>).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.requirements_array(requirement_string) ⇒ Object



23
# File 'lib/dependabot/requirement.rb', line 23

def self.requirements_array(requirement_string); end

Instance Method Details

#constraintsObject



27
28
29
# File 'lib/dependabot/requirement.rb', line 27

def constraints
  requirements.map { |op, version| "#{op} #{version}" }
end

#handle_greater_than_for_min(version) ⇒ Object



88
89
90
# File 'lib/dependabot/requirement.rb', line 88

def handle_greater_than_for_min(version)
  version
end

#handle_greater_than_or_equal_for_min(version) ⇒ Object



83
84
85
# File 'lib/dependabot/requirement.rb', line 83

def handle_greater_than_or_equal_for_min(version)
  version
end

#handle_less_than_max(version) ⇒ Object



104
105
106
# File 'lib/dependabot/requirement.rb', line 104

def handle_less_than_max(version)
  version
end

#handle_less_than_or_equal_for_max(version) ⇒ Object



99
100
101
# File 'lib/dependabot/requirement.rb', line 99

def handle_less_than_or_equal_for_max(version)
  version
end

#handle_max_operator(operator, version) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/dependabot/requirement.rb', line 73

def handle_max_operator(operator, version)
  case operator
  when "<=" then handle_less_than_or_equal_for_max(version)
  when "<"  then handle_less_than_max(version)
  when "~>" then handle_tilde_pessimistic_max(version)
  end
end

#handle_min_operator(operator, version) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/dependabot/requirement.rb', line 63

def handle_min_operator(operator, version)
  case operator
  when ">=" then handle_greater_than_or_equal_for_min(version)
  when ">"  then handle_greater_than_for_min(version)
  when "~>" then handle_tilde_pessimistic_for_min(version)
  end
end

#handle_tilde_pessimistic_for_min(version) ⇒ Object



93
94
95
# File 'lib/dependabot/requirement.rb', line 93

def handle_tilde_pessimistic_for_min(version)
  version
end

#handle_tilde_pessimistic_max(version) ⇒ Object



109
110
111
112
113
114
115
116
117
118
# File 'lib/dependabot/requirement.rb', line 109

def handle_tilde_pessimistic_max(version)
  case version.segments.length
  when 1
    bump_major_segment(version)
  when 2
    bump_minor_segment(version)
  else
    bump_version(version)
  end
end

#max_versionObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dependabot/requirement.rb', line 48

def max_version
  # Select constraints with maximum operators
  max_constraints = requirements.select { |op, _version| MAXIMUM_OPERATORS.include?(op) }

  # Process each maximum constraint using the respective handler
  effective_max_versions = max_constraints.filter_map do |op, version|
    handle_max_operator(op, version.is_a?(Dependabot::Version) ? version : Dependabot::Version.new(version))
  end

  # Return the minimum among the effective maximum constraints
  Dependabot::Version.new(effective_max_versions.min) if effective_max_versions.any?
end

#min_versionObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dependabot/requirement.rb', line 33

def min_version
  # Select constraints with minimum operators
  min_constraints = requirements.select { |op, _version| MINIMUM_OPERATORS.include?(op) }

  # Process each minimum constraint using the respective handler
  effective_min_versions = min_constraints.filter_map do |op, version|
    handle_min_operator(op, version.is_a?(Dependabot::Version) ? version : Dependabot::Version.new(version))
  end

  # Return the maximum among the effective minimum constraints
  Dependabot::Version.new(effective_min_versions.max) if effective_min_versions.any?
end