Class: Dependabot::Utils::Elixir::Requirement
- Inherits:
-
Gem::Requirement
- Object
- Gem::Requirement
- Dependabot::Utils::Elixir::Requirement
- Defined in:
- lib/dependabot/utils/elixir/requirement.rb
Constant Summary collapse
- AND_SEPARATOR =
/\s+and\s+/.freeze
- OR_SEPARATOR =
/\s+or\s+/.freeze
- OPS =
Add the double-equality matcher to the list of allowed operations
OPS.merge("==" => ->(v, r) { v == r })
- PATTERN_RAW =
"\\s*(#{quoted})?\\s*(#{Utils::Elixir::Version::VERSION_PATTERN})\\s*"
- PATTERN =
/\A#{PATTERN_RAW}\z/.freeze
Class Method Summary collapse
-
.parse(obj) ⇒ Object
Override the parser to create Utils::Elixir::Versions.
-
.requirements_array(requirement_string) ⇒ Object
Returns an array of requirements.
Instance Method Summary collapse
Class Method Details
.parse(obj) ⇒ Object
Override the parser to create Utils::Elixir::Versions
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dependabot/utils/elixir/requirement.rb', line 31 def self.parse(obj) if obj.is_a?(Gem::Version) return ["=", Utils::Elixir::Version.new(obj.to_s)] end 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] || "=", Utils::Elixir::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.
23 24 25 26 27 28 |
# File 'lib/dependabot/utils/elixir/requirement.rb', line 23 def self.requirements_array(requirement_string) requirement_string.strip.split(OR_SEPARATOR).map do |req_string| requirements = req_string.strip.split(AND_SEPARATOR) new(requirements) end end |