Class: Dependabot::Nuget::Requirement

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*requirements) ⇒ Requirement

Returns a new instance of Requirement.


31
32
33
34
35
36
37
# File 'lib/dependabot/nuget/requirement.rb', line 31

def initialize(*requirements)
  requirements = requirements.flatten.flat_map do |req_string|
    convert_dotnet_constraint_to_ruby_constraint(req_string)
  end

  super(requirements)
end

Class Method Details

.parse(obj) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dependabot/nuget/requirement.rb', line 11

def self.parse(obj)
  return ["=", Nuget::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] || "=", Nuget::Version.new(matches[2])]
end

.requirements_array(requirement_string) ⇒ Object

For consistency with other langauges, we define a requirements array. Dotnet doesn't have an `OR` separator for requirements, so it always contains a single element.


27
28
29
# File 'lib/dependabot/nuget/requirement.rb', line 27

def self.requirements_array(requirement_string)
  [new(requirement_string)]
end

Instance Method Details

#satisfied_by?(version) ⇒ Boolean

Returns:

  • (Boolean)

39
40
41
42
# File 'lib/dependabot/nuget/requirement.rb', line 39

def satisfied_by?(version)
  version = Nuget::Version.new(version.to_s)
  super
end