Class: Dependabot::Vcpkg::Requirement

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

Constant Summary collapse

OPERATOR_PATTERN =

Gem::Requirement::OPS lists > before >=, which would make the shorter operator win against vcpkg's permissive version syntax. Longest first keeps >=1.2.3 intact.

T.let(
  OPS.keys.sort_by { |op| -op.length }.map { |op| Regexp.quote(op) }.join("|").freeze,
  String
)
PATTERN_RAW =
T.let(
  "\\s*(#{OPERATOR_PATTERN})?\\s*(#{Version::REQUIREMENT_VERSION_PATTERN.source})\\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.



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

def initialize(*requirements)
  requirements = requirements.flatten.flat_map do |req_string|
    next req_string unless req_string.is_a?(String)

    req_string.split(",").map(&:strip).reject(&:empty?)
  end

  super(requirements)
end

Class Method Details

.parse(obj) ⇒ Object

Raises:

  • (BadRequirementError)


38
39
40
41
42
43
44
45
46
47
# File 'lib/dependabot/vcpkg/requirement.rb', line 38

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

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

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

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

.requirements_array(requirement_string) ⇒ Object



31
32
33
# File 'lib/dependabot/vcpkg/requirement.rb', line 31

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