module Polisher::RPM::RequirementComparison

Public Instance Methods

==(other) click to toggle source
# File lib/polisher/rpm/requirement/comparison.rb, line 9
def ==(other)
  @br        == other.br &&
  @name      == other.name &&
  @condition == other.condition &&
  @version   == other.version
end
gcd(versions) click to toggle source

Greatest Common Denominator, Max version in list that is less than the local version

# File lib/polisher/rpm/requirement/comparison.rb, line 18
def gcd(versions)
  require 'versionomy'
  lversion = Versionomy.parse(version)
  versions.collect { |v| Versionomy.parse(v) }
          .sort { |a, b| a <=> b }.reverse
          .find { |v| v < lversion }.to_s
end
matches?(dep) click to toggle source

Return bool indicating if requirement matches specified depedency.

Comparison mechanism will depend on type of class passed to this. Valid types include

  • Polisher::RPM::Requirements

  • ::Gem::Dependency

# File lib/polisher/rpm/requirement/comparison.rb, line 83
def matches?(dep)
  require 'gem2rpm'

  return self == dep      if dep.is_a?(self.class)
  raise ArgumentError unless dep.is_a?(::Gem::Dependency)

  return false if !gem? || gem_name != dep.name
  return true  if  version.nil?

  Gem2Rpm::Helpers.expand_requirement([dep.requirement.to_s.split])
                  .any? { |req| req.first == condition && req.last.to_s == version }
end
max_failing_version(versions = nil) click to toggle source

Max gem version for which this dependency fails

Can’t automatically deduce in ‘>=’, and ‘=’ cases, so if that is the conditional we require a version list, and will return the gcd from it

# File lib/polisher/rpm/requirement/comparison.rb, line 66
def max_failing_version(versions = nil)
  raise ArgumentError if version.nil?      ||
                         condition == '<=' ||
                         condition == '<'
  return version      if condition == '>'

  raise ArgumentError if versions.nil?
  gcd(versions)
end
max_satisfying_version(versions = nil) click to toggle source

Max gem version which satisfies this dependency

Can’t automatically deduce in ‘<’ case, so if that is the conditional we require a version list, and will return the gcd from it

# File lib/polisher/rpm/requirement/comparison.rb, line 41
def max_satisfying_version(versions = nil)
  return Float::INFINITY if version.nil?      ||
                            condition == '>'  ||
                            condition == '>='
  return version         if condition == '='  ||
                            condition == '<='

  raise ArgumentError    if versions.nil?
  gcd(versions)
end
min_failing_version() click to toggle source

Minimum gem version for which this dependency fails

# File lib/polisher/rpm/requirement/comparison.rb, line 53
def min_failing_version
  require 'versionomy'
  raise ArgumentError if version.nil?
  return "0.0"        if condition == '>'  ||
                         condition == '>='
  return version      if condition == '<'
  Versionomy.parse(version).bump(:tiny).to_s # condition == '<=' and '='
end
min_satisfying_version() click to toggle source

Minimum gem version which satisfies this dependency

# File lib/polisher/rpm/requirement/comparison.rb, line 27
def min_satisfying_version
  require 'versionomy'
  return "0.0"   if version.nil?      ||
                    condition == '<'  ||
                    condition == '<='
  return version if condition == '='  ||
                    condition == '>='
  Versionomy.parse(version).bump(:tiny).to_s # condition == '>'
end