Class: Dependabot::Terraform::Requirement

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

Constant Summary collapse

OPERATORS =

Override regex PATTERN from Gem::Requirement to add support for the optional ā€˜vā€™ prefix to release tag names, which Terraform supports. www.terraform.io/docs/registry/modules/publish.html#requirements

T.let(OPS.keys.map { |key| Regexp.quote(key) }.join("|").freeze, String)
PATTERN_RAW =
T.let("\\s*(#{OPERATORS})?\\s*v?(#{Gem::Version::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.



47
48
49
50
51
52
53
# File 'lib/dependabot/terraform/requirement.rb', line 47

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

  super(requirements)
end

Class Method Details

.parse(obj) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dependabot/terraform/requirement.rb', line 23

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] || "=", Terraform::Version.new(matches[2])]
end

.requirements_array(requirement_string) ⇒ Object



40
41
42
# File 'lib/dependabot/terraform/requirement.rb', line 40

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