Class: Dependabot::Dep::Requirement
- Inherits:
-
Gem::Requirement
- Object
- Gem::Requirement
- Dependabot::Dep::Requirement
- Defined in:
- lib/dependabot/dep/requirement.rb
Constant Summary collapse
- WILDCARD_REGEX =
/(?:\.|^)[xX*]/.freeze
- OR_SEPARATOR =
/(?<=[a-zA-Z0-9*])\s*\|{2}/.freeze
- PATTERN_RAW =
"\\s*(#{quoted})?\\s*(#{version_pattern})\\s*"
- PATTERN =
/\A#{PATTERN_RAW}\z/.freeze
Class Method Summary collapse
-
.parse(obj) ⇒ Object
Use Dep::Version rather than Gem::Version to ensure that pre-release versions aren’t transformed.
-
.requirements_array(requirement_string) ⇒ Object
Returns an array of requirements.
Instance Method Summary collapse
-
#initialize(*requirements) ⇒ Requirement
constructor
A new instance of Requirement.
Constructor Details
#initialize(*requirements) ⇒ Requirement
Returns a new instance of Requirement.
50 51 52 53 54 55 56 57 58 |
# File 'lib/dependabot/dep/requirement.rb', line 50 def initialize(*requirements) requirements = requirements.flatten.flat_map do |req_string| req_string.split(",").map do |r| convert_go_constraint_to_ruby_constraint(r.strip) end end super(requirements) end |
Class Method Details
.parse(obj) ⇒ Object
Use Dep::Version rather than Gem::Version to ensure that pre-release versions aren’t transformed.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dependabot/dep/requirement.rb', line 27 def self.parse(obj) return ["=", Dep::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] || "=", Dep::Version.new(matches[2])] end |
.requirements_array(requirement_string) ⇒ Object
Returns an array of requirements. At least one requirement from the returned array must be satisfied for a version to be valid.
42 43 44 45 46 47 48 |
# File 'lib/dependabot/dep/requirement.rb', line 42 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 |