Class: Capsium::Package::VersionRange

Inherits:
Object
  • Object
show all
Defined in:
lib/capsium/package/version.rb,
sig/capsium/package/version.rbs

Overview

A semver range for metadata.dependencies (ARCHITECTURE.md section 4a): "*", exact versions, wildcards/partials, caret, tilde, comparison operators and comma/space conjunctions.

Constant Summary collapse

NUMERIC_PART =

Returns:

  • (Regexp)
/\A(\d+)(?:\.(\d+)|\.(?:x|X|\*))?(?:\.(?:\d+|x|X|\*))?(?:-[^\s,]+)?\z/
WILDCARD_PART =

Returns:

  • (Regexp)
/\A(?:x|X|\*)\z/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bounds) ⇒ VersionRange

Returns a new instance of VersionRange.

Parameters:

  • bounds (Array[[String, Version]])


182
183
184
# File 'lib/capsium/package/version.rb', line 182

def initialize(bounds)
  @bounds = bounds
end

Class Method Details

.parse(string) ⇒ VersionRange

Parameters:

  • string (String)

Returns:



88
89
90
91
92
93
# File 'lib/capsium/package/version.rb', line 88

def self.parse(string)
  terms = string.to_s.strip.split(/[,\s]+/).reject(&:empty?)
  return new([[">=", Version.new(0, 0, 0)]]) if terms.empty? || terms == ["*"]

  new(terms.flat_map { |term| expand_term(term) })
end

Instance Method Details

#satisfied_by?(version) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


186
187
188
189
# File 'lib/capsium/package/version.rb', line 186

def satisfied_by?(version)
  version = Version.parse(version) unless version.is_a?(Version)
  @bounds.all? { |operator, bound| holds?(operator, version <=> bound) }
end