class Chef::Provider::Package::Yum::RPMVersion

Attributes

e[R]
epoch[R]
r[R]
release[R]
v[R]
version[R]

Public Class Methods

new(*args) click to toggle source
# File lib/chef/provider/package/yum/rpm_utils.rb, line 234
def initialize(*args)
  if args.size == 1
    @e, @v, @r = RPMUtils.version_parse(args[0])
  elsif args.size == 3
    @e = args[0].to_i
    @v = args[1]
    @r = args[2]
  else
    raise ArgumentError, "Expecting either 'epoch-version-release' or 'epoch, " \
      "version, release'"
  end
end
parse(*args) click to toggle source
# File lib/chef/provider/package/yum/rpm_utils.rb, line 251
def self.parse(*args)
  new(*args)
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/chef/provider/package/yum/rpm_utils.rb, line 255
def <=>(other)
  compare_versions(other)
end
compare(other) click to toggle source
# File lib/chef/provider/package/yum/rpm_utils.rb, line 259
def compare(other)
  compare_versions(other, false)
end
evr() click to toggle source
# File lib/chef/provider/package/yum/rpm_utils.rb, line 276
def evr
  "#{@e}:#{@v}-#{@r}"
end
partial_compare(other) click to toggle source
# File lib/chef/provider/package/yum/rpm_utils.rb, line 263
def partial_compare(other)
  compare_versions(other, true)
end
to_s() click to toggle source

RPM::Version rpm_version_to_s equivalent

# File lib/chef/provider/package/yum/rpm_utils.rb, line 268
def to_s
  if @r.nil?
    @v
  else
    "#{@v}-#{@r}"
  end
end

Private Instance Methods

compare_versions(y, partial = false) click to toggle source

Rough RPM::Version rpm_version_cmp equivalent - except much slower :)

partial lets epoch and version segment equality be good enough to return equal, eg:

2:1.2-1 == 2:1.2 2:1.2-1 == 2:

# File lib/chef/provider/package/yum/rpm_utils.rb, line 289
def compare_versions(y, partial = false)
  x = self

  # compare epoch
  if (x.e.nil? == false && x.e > 0) && y.e.nil?
    return 1
  elsif x.e.nil? && (y.e.nil? == false && y.e > 0)
    return -1
  elsif x.e.nil? == false && y.e.nil? == false
    if x.e < y.e
      return -1
    elsif x.e > y.e
      return 1
    end
  end

  # compare version
  if partial && (x.v.nil? || y.v.nil?)
    return 0
  elsif x.v.nil? == false && y.v.nil?
    return 1
  elsif x.v.nil? && y.v.nil? == false
    return -1
  elsif x.v.nil? == false && y.v.nil? == false
    cmp = RPMUtils.rpmvercmp(x.v, y.v)
    return cmp if cmp != 0
  end

  # compare release
  if partial && (x.r.nil? || y.r.nil?)
    return 0
  elsif x.r.nil? == false && y.r.nil?
    return 1
  elsif x.r.nil? && y.r.nil? == false
    return -1
  elsif x.r.nil? == false && y.r.nil? == false
    cmp = RPMUtils.rpmvercmp(x.r, y.r)
    return cmp
  end

  0
end