# class Chef::Provider::Package::Yum::RPMDependency

Simple implementation from rpm and ruby-rpm reference code

### Attributes

flag[R]
name[R]
version[R]

### Public Class Methods

new(*args) click to toggle source

    # File lib/chef/provider/package/yum.rb, line 420
    def initialize(*args)
      if args.size == 3
        @name = args[0]
        @version = RPMVersion.new(args[1])
        # Our requirement to other dependencies
        @flag = args[2] || :==
      elsif args.size == 5
        @name = args[0]
        e = args[1].to_i
        v = args[2]
        r = args[3]
        @version = RPMVersion.new(e,v,r)
        @flag = args[4] || :==
      else
        raise ArgumentError, "Expecting either 'name, epoch-version-release, flag' or " +
                             "'name, epoch, version, release, flag'"
      end
    end

parse(string) click to toggle source

Parses 2 forms:

“mtr >= 2:0.71-3.0” “mta”

    # File lib/chef/provider/package/yum.rb, line 444
    def self.parse(string)
      if string =~ %r{^(\S+)\s+(>|>=|=|==|<=|<)\s+(\S+)$}
        name = $1
        if $2 == "="
          flag = :==
        else
          flag = :"#{$2}"
        end
        version = $3

        return self.new(name, version, flag)
      else
        name = string
        return self.new(name, nil, nil)
      end
    end

### Public Instance Methods

satisfy?(y) click to toggle source

Test if another RPMDependency satisfies our requirements

    # File lib/chef/provider/package/yum.rb, line 462
    def satisfy?(y)
      unless y.kind_of?(RPMDependency)
        raise ArgumentError, "Expecting an RPMDependency object"
      end

      x = self

      # Easy!
      if x.name != y.name
        return false
      end

      # Partial compare
      #
      # eg: x.version 2.3 == y.version 2.3-1
      sense = x.version.partial_compare(y.version)

      # Thanks to rpmdsCompare() rpmds.c
      if sense < 0 and (x.flag == :> || x.flag == :>=) || (y.flag == :<= || y.flag == :<)
        return true
      elsif sense > 0 and (x.flag == :< || x.flag == :<=) || (y.flag == :>= || y.flag == :>)
        return true
      elsif sense == 0 and (
        ((x.flag == :== or x.flag == :<= or x.flag == :>=) and (y.flag == :== or y.flag == :<= or y.flag == :>=)) or
        (x.flag == :< and y.flag == :<) or
        (x.flag == :> and y.flag == :>)
      )
        return true
      end

      return false
    end