class Solve::Constraint

def ==(other)

Returns:
  • (Boolean) -

Parameters:
  • other (Object) --
def ==(other)
  other.is_a?(self.class) &&
    self.operator == other.operator &&
    self.version == other.version
end

def coerce(object)

Returns:
  • (Constraint) -

Parameters:
  • (Constraint, String) --
def coerce(object)
  if object.nil?
    Semverse::DEFAULT_CONSTRAINT
  else
    object.is_a?(self) ? object : new(object)
  end
end

def compare(target)

Returns:
  • (Boolean) -

Parameters:
  • target (Semverse::Version) --
def compare(target)
  COMPARE_FUNS.fetch(operator_type).call(self, target)
end

def compare_approx(constraint, target_version)

Returns:
  • (Boolean) -

Parameters:
  • target_version (Semverse::Version) --
  • constraint (Semverse::Constraint) --
def compare_approx(constraint, target_version)
  min = constraint.version
  max = if constraint.patch.nil?
    Semverse::Version.new([min.major + 1, 0, 0, 0])
  elsif constraint.build
    identifiers = constraint.version.identifiers(:build)
    replace     = identifiers.last.to_i.to_s == identifiers.last.to_s ? "-" : nil
    Semverse::Version.new([min.major, min.minor, min.patch, min.pre_release, identifiers.fill(replace, -1).join('.')])
  elsif constraint.pre_release
    identifiers = constraint.version.identifiers(:pre_release)
    replace     = identifiers.last.to_i.to_s == identifiers.last.to_s ? "-" : nil
    Semverse::Version.new([min.major, min.minor, min.patch, identifiers.fill(replace, -1).join('.')])
  else
    Semverse::Version.new([min.major, min.minor + 1, 0, 0])
  end
  min <= target_version && target_version < max
end

def compare_equal(constraint, target_version)

Returns:
  • (Boolean) -

Parameters:
  • target_version (Semverse::Version) --
  • constraint (Semverse::Constraint) --
def compare_equal(constraint, target_version)
  target_version == constraint.version
end

def compare_gt(constraint, target_version)

Returns:
  • (Boolean) -

Parameters:
  • target_version (Semverse::Version) --
  • constraint (Semverse::Constraint) --
def compare_gt(constraint, target_version)
  target_version > constraint.version
end

def compare_gte(constraint, target_version)

Returns:
  • (Boolean) -

Parameters:
  • target_version (Semverse::Version) --
  • constraint (Semverse::Constraint) --
def compare_gte(constraint, target_version)
  target_version >= constraint.version
end

def compare_lt(constraint, target_version)

Returns:
  • (Boolean) -

Parameters:
  • target_version (Semverse::Version) --
  • constraint (Semverse::Constraint) --
def compare_lt(constraint, target_version)
  target_version < constraint.version
end

def compare_lte(constraint, target_version)

Returns:
  • (Boolean) -

Parameters:
  • target_version (Semverse::Version) --
  • constraint (Semverse::Constraint) --
def compare_lte(constraint, target_version)
  target_version <= constraint.version
end

def greedy_match?(target_version)

Parameters:
  • target_version (Semverse::Version) --
def greedy_match?(target_version)
  operator_type !~ /less/ && target_version.pre_release? && !version.pre_release?
end

def initialize(constraint = nil)

Parameters:
  • constraint (#to_s) --
def initialize(constraint = nil)
  constraint = constraint.to_s
  if constraint.nil? || constraint.empty?
    constraint = '>= 0.0.0'
  end
  @operator, @major, @minor, @patch, @pre_release, @build = self.class.split(constraint)
  unless operator_type == :approx
    @minor ||= 0
    @patch ||= 0
  end
  @version = Semverse::Version.new([
    self.major,
    self.minor,
    self.patch,
    self.pre_release,
    self.build,
  ])
end

def inspect

def inspect
  "#<#{self.class.to_s} #{to_s}>"
end

def operator_type

Returns:
  • (Symbol) -
def operator_type
  unless type = OPERATOR_TYPES.fetch(operator)
    raise RuntimeError, "unknown operator type: #{operator}"
  end
  type
end

def satisfies?(target)

Returns:
  • (Boolean) -

Parameters:
  • target (Semverse::Version, #to_s) --
def satisfies?(target)
  target = Semverse::Version.coerce(target)
  return false if !version.zero? && greedy_match?(target)
  compare(target)
end

def split(constraint)

Returns:
  • (Array, nil) -

Other tags:
    Example: splitting a string without a valid version string -
    Example: splitting a string without a constraint operator -
    Example: splitting a string with a constraint operator and valid version string -

Parameters:
  • constraint (#to_s) --
def split(constraint)
  if constraint =~ /^[0-9]/
    operator = "="
    version  = constraint
  else
    _, operator, version = REGEXP.match(constraint).to_a
  end
  if operator.nil?
    raise Errors::InvalidConstraintFormat.new(constraint)
  end
  split_version = case version.to_s
  when /^(\d+)\.(\d+)\.(\d+)(-([0-9a-z\-\.]+))?(\+([0-9a-z\-\.]+))?$/i
    [ $1.to_i, $2.to_i, $3.to_i, $5, $7 ]
  when /^(\d+)\.(\d+)\.(\d+)?$/
    [ $1.to_i, $2.to_i, $3.to_i, nil, nil ]
  when /^(\d+)\.(\d+)?$/
    [ $1.to_i, $2.to_i, nil, nil, nil ]
  when /^(\d+)$/
    [ $1.to_i, nil, nil, nil, nil ]
  else
    raise Errors::InvalidConstraintFormat.new(constraint)
  end
  [ operator, split_version ].flatten
end

def to_s

def to_s
  out =  "#{operator} #{major}"
  out << ".#{minor}" if minor
  out << ".#{patch}" if patch
  out << "-#{pre_release}" if pre_release
  out << "+#{build}" if build
  out
end