class Dependabot::Elm::Requirement

Constants

ELM_EXACT_PATTERN
ELM_PATTERN
ELM_PATTERN_RAW

Public Class Methods

new(*requirements) click to toggle source
Calls superclass method
# File lib/dependabot/elm/requirement.rb, line 21
def initialize(*requirements)
  requirements = requirements.flatten.flat_map do |req_string|
    raise BadRequirementError, "Nil requirement not supported in Elm" if req_string.nil?

    req_string.split(",").map(&:strip).map do |r|
      convert_elm_constraint_to_ruby_constraint(r)
    end
  end

  super(requirements)
end
requirements_array(requirement_string) click to toggle source

Returns an array of requirements. At least one requirement from the returned array must be satisfied for a version to be valid.

# File lib/dependabot/elm/requirement.rb, line 17
def self.requirements_array(requirement_string)
  [new(requirement_string)]
end

Public Instance Methods

satisfied_by?(version) click to toggle source
Calls superclass method
# File lib/dependabot/elm/requirement.rb, line 33
def satisfied_by?(version)
  version = Elm::Version.new(version.to_s)
  super
end

Private Instance Methods

convert_elm_constraint_to_ruby_constraint(obj) click to toggle source

Override the parser to create Elm::Versions and return an array of parsed requirements

# File lib/dependabot/elm/requirement.rb, line 42
def convert_elm_constraint_to_ruby_constraint(obj)
  # If a version is given this is an equals requirement
  return obj if ELM_EXACT_PATTERN.match?(obj.to_s)

  return obj unless (matches = ELM_PATTERN.match(obj.to_s))

  # If the two versions specified are identical this is an equals
  # requirement
  return matches[4] if matches[1] == matches[4] && matches[3] == "<="

  [
    [matches[2].tr("<", ">"), matches[1]].join(" "),
    [matches[3], matches[4]].join(" ")
  ]
end