Class: Dependabot::GoModules::Requirement

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

Constant Summary collapse

WILDCARD_REGEX =
/(?:\.|^)[xX*]/
OR_SEPARATOR =
/(?<=[a-zA-Z0-9*])\s*\|{2}/
PATTERN_RAW =
T.let("\\s*(#{quoted})?\\s*(#{version_pattern})\\s*".freeze, String)
PATTERN =
/\A#{PATTERN_RAW}\z/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*requirements) ⇒ Requirement

Returns a new instance of Requirement.



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

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

  super(requirements)
end

Class Method Details

.parse(obj) ⇒ Object



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

def self.parse(obj)
  return ["=", 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] || "=", Version.new(matches[2])]
end

.requirements_array(requirement_string) ⇒ Object



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

def self.requirements_array(requirement_string)
  return [new(nil)] if requirement_string.nil?

  requirement_string.strip.split(OR_SEPARATOR).map do |req_string|
    new(req_string)
  end
end