Class: Dependabot::Cargo::Requirement

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

Constant Summary collapse

PATTERN_RAW =
"\\s*(#{quoted})?\\s*(#{version_pattern})\\s*".freeze
PATTERN =
/\A#{PATTERN_RAW}\z/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*requirements) ⇒ Requirement

Returns a new instance of Requirement.



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

def initialize(*requirements)
  requirements = requirements.flatten.flat_map do |req_string|
    req_string.split(",").map(&:strip).map do |r|
      convert_rust_constraint_to_ruby_constraint(r.strip)
    end
  end

  super(requirements)
end

Class Method Details

.parse(obj) ⇒ Object

Use Cargo::Version rather than Gem::Version to ensure that pre-release versions aren’t transformed.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dependabot/cargo/requirement.rb', line 29

def self.parse(obj)
  return ["=", Cargo::Version.new(obj.to_s)] if obj.is_a?(Gem::Version)

  unless (matches = PATTERN.match(obj.to_s))
    msg = "Illformed requirement [#{obj.inspect}]"
    raise BadRequirementError, msg
  end

  return DefaultRequirement if matches[1] == ">=" && matches[2] == "0"

  [matches[1] || "=", Cargo::Version.new(T.must(matches[2]))]
end

.requirements_array(requirement_string) ⇒ Object



46
47
48
# File 'lib/dependabot/cargo/requirement.rb', line 46

def self.requirements_array(requirement_string)
  [new(requirement_string)]
end