Module: Philiprehberger::Semver::Range

Defined in:
lib/philiprehberger/semver/range.rb

Overview

Evaluates version constraint strings against a Version.

Supports comma-separated constraints using the operators >=, <=, >, <, =, ~> (pessimistic) and ^ (compatible). A bare version string (no operator) is treated as exact match.

Constant Summary collapse

OPERATOR_PREFIX_REGEX =
/\A\s*[!~=<>^]/
CONSTRAINT_REGEX =
/\A\s*(>=|<=|>|<|=|~>|\^)\s*(.+)\z/
COMPARISON_OPS =
{ '>=' => :>=, '<=' => :<=, '>' => :>, '<' => :<, '=' => :== }.freeze

Class Method Summary collapse

Class Method Details

.satisfies?(version, constraint) ⇒ Boolean

Check whether version satisfies every comma-separated constraint.

Parameters:

  • version (String, Version)

    the version to test

  • constraint (String)

    one or more comma-separated constraints

Returns:

  • (Boolean)

    true if every part of constraint is satisfied

Raises:

  • (Error)

    if version is invalid or constraint is malformed



20
21
22
23
24
25
26
27
# File 'lib/philiprehberger/semver/range.rb', line 20

def self.satisfies?(version, constraint)
  ver = version.is_a?(Version) ? version : Parser.parse(version)
  raise Error, 'Constraint cannot be empty' if constraint.nil? || constraint.strip.empty?

  constraint.split(',').all? do |part|
    check_constraint(ver, part.strip)
  end
end