Class: Dependabot::Hex::Requirement
- Inherits:
-
Requirement
- Object
- Requirement
- Dependabot::Hex::Requirement
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/hex/requirement.rb
Constant Summary collapse
- AND_SEPARATOR =
/\s+and\s+/
- OR_SEPARATOR =
/\s+or\s+/
- OPS =
Add the double-equality matcher to the list of allowed operations
OPS.merge("==" => ->(v, r) { v == r })
- PATTERN_RAW =
"\\s*(#{quoted})?\\s*(#{Hex::Version::VERSION_PATTERN})\\s*".freeze
- PATTERN =
/\A#{PATTERN_RAW}\z/
Class Method Summary collapse
-
.parse(obj) ⇒ Object
Override the parser to create Hex::Versions.
- .requirements_array(requirement_string) ⇒ Object
Instance Method Summary collapse
-
#initialize(*requirements) ⇒ Requirement
constructor
Patches Gem::Requirement to make it accept requirement strings like “~> 4.2.5, >= 4.2.5.1” without first needing to split them.
- #satisfied_by?(version) ⇒ Boolean
Constructor Details
#initialize(*requirements) ⇒ Requirement
Patches Gem::Requirement to make it accept requirement strings like “~> 4.2.5, >= 4.2.5.1” without first needing to split them.
38 39 40 41 42 43 44 |
# File 'lib/dependabot/hex/requirement.rb', line 38 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
Override the parser to create Hex::Versions
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dependabot/hex/requirement.rb', line 47 def self.parse(obj) return ["=", Hex::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] || "=", Hex::Version.new(T.must(matches[2]))] end |
.requirements_array(requirement_string) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/dependabot/hex/requirement.rb', line 29 def self.requirements_array(requirement_string) T.must(requirement_string).strip.split(OR_SEPARATOR).map do |req_string| requirements = req_string.strip.split(AND_SEPARATOR) new(requirements) end end |