Class: Dependabot::Composer::Requirement

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

Constant Summary collapse

AND_SEPARATOR =
/(?<=[a-zA-Z0-9*])(?<!\sas)[\s,]+(?![\s,]*[|-]|as)/.freeze
OR_SEPARATOR =
/(?<=[a-zA-Z0-9*])[\s,]*\|\|?\s*/.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*requirements) ⇒ Requirement

Returns a new instance of Requirement.


25
26
27
28
29
30
31
32
# File 'lib/dependabot/composer/requirement.rb', line 25

def initialize(*requirements)
  requirements =
    requirements.flatten.
    flat_map { |req_string| req_string.split(AND_SEPARATOR) }.
    flat_map { |req| convert_php_constraint_to_ruby_constraint(req) }

  super(requirements)
end

Class Method Details

.parse(obj) ⇒ Object


12
13
14
15
# File 'lib/dependabot/composer/requirement.rb', line 12

def self.parse(obj)
  new_obj = obj.gsub(/@\w+/, "").gsub(/[a-z0-9\-_\.]*\sas\s+/i, "")
  super(new_obj)
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.


19
20
21
22
23
# File 'lib/dependabot/composer/requirement.rb', line 19

def self.requirements_array(requirement_string)
  requirement_string.strip.split(OR_SEPARATOR).map do |req_string|
    new(req_string)
  end
end