Class: Dependabot::Pub::Requirement
- Inherits:
-
Requirement
- Object
- Requirement
- Dependabot::Pub::Requirement
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/pub/requirement.rb
Constant Summary collapse
- PATTERN_RAW =
T.let("\\s*(#{quoted})?\\s*(#{version_pattern})\\s*".freeze, String)
- PATTERN =
/\A#{PATTERN_RAW}\z/
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*requirements, raw_constraint: nil) ⇒ Requirement
constructor
A new instance of Requirement.
- #to_s ⇒ Object
Constructor Details
#initialize(*requirements, raw_constraint: nil) ⇒ Requirement
Returns a new instance of Requirement.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dependabot/pub/requirement.rb', line 55 def initialize(*requirements, raw_constraint: nil) requirements = requirements.flatten.flat_map do |req_string| req_string.split(",").map(&:strip).map do |r| convert_dart_constraint_to_ruby_constraint(r.strip) end end super(requirements) @raw_constraint = raw_constraint end |
Class Method Details
.parse(obj) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dependabot/pub/requirement.rb', line 33 def self.parse(obj) return ["=", Pub::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] || "=", Pub::Version.new(T.must(matches[2]))] end |
.requirements_array(requirement_string) ⇒ Object
50 51 52 |
# File 'lib/dependabot/pub/requirement.rb', line 50 def self.requirements_array(requirement_string) [new(T.must(requirement_string))] end |
Instance Method Details
#to_s ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/dependabot/pub/requirement.rb', line 67 def to_s if @raw_constraint.nil? as_list.join " " else @raw_constraint end end |