Class: Dependabot::Terraform::Requirement

Inherits:
Gem::Requirement
  • Object
show all
Defined in:
lib/dependabot/terraform/requirement.rb

Class Method Summary collapse

Class Method Details

.parse(obj) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dependabot/terraform/requirement.rb', line 10

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

For consistency with other langauges, we define a requirements array. Terraform doesn't have an `OR` separator for requirements, so it always contains a single element.


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

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