# class Chef::Provider::Package::Yum::RPMDb

Simple storage for RPMPackage objects - keeps them unique and sorted

### Public Class Methods

new() click to toggle source

    # File lib/chef/provider/package/yum.rb, line 513
    def initialize
      # package name => [ RPMPackage, RPMPackage ] of different versions
      @rpms = Hash.new
      # package nevra => RPMPackage for lookups
      @index = Hash.new
      # provide name (aka feature) => [RPMPackage, RPMPackage] each providing this feature
      @provides = Hash.new
      # RPMPackages listed as available
      @available = Set.new
      # RPMPackages listed as installed
      @installed = Set.new
    end

### Public Instance Methods

<<(*args) click to toggle source

    # File lib/chef/provider/package/yum.rb, line 584
    def <<(*args)
      self.push(args)
    end

[](package_name) click to toggle source

    # File lib/chef/provider/package/yum.rb, line 526
    def [](package_name)
      self.lookup(package_name)
    end

available?(package) click to toggle source

    # File lib/chef/provider/package/yum.rb, line 617
    def available?(package)
      @available.include?(package)
    end

available_size() click to toggle source

    # File lib/chef/provider/package/yum.rb, line 609
    def available_size
      @available.size
    end

clear() click to toggle source

    # File lib/chef/provider/package/yum.rb, line 588
    def clear
      @rpms.clear
      @index.clear
      @provides.clear
      clear_available
      clear_installed
    end

clear_available() click to toggle source

    # File lib/chef/provider/package/yum.rb, line 596
    def clear_available
      @available.clear
    end

clear_installed() click to toggle source

    # File lib/chef/provider/package/yum.rb, line 600
    def clear_installed
      @installed.clear
    end

installed?(package) click to toggle source

    # File lib/chef/provider/package/yum.rb, line 621
    def installed?(package)
      @installed.include?(package)
    end

installed_size() click to toggle source

    # File lib/chef/provider/package/yum.rb, line 613
    def installed_size
      @installed.size
    end

length()
Alias for: size
lookup(package_name) click to toggle source

Lookup package_name and return a descending array of package objects

    # File lib/chef/provider/package/yum.rb, line 531
    def lookup(package_name)
      pkgs = @rpms[package_name]
      if pkgs
        return pkgs.sort.reverse
      else
        return nil
      end
    end

lookup_provides(provide_name) click to toggle source

    # File lib/chef/provider/package/yum.rb, line 540
    def lookup_provides(provide_name)
      @provides[provide_name]
    end

push(*args) click to toggle source

Using the package name as a key, and nevra for an index, keep a unique list of packages. The available/installed state can be overwritten for existing packages.

    # File lib/chef/provider/package/yum.rb, line 546
    def push(*args)
      args.flatten.each do |new_rpm|
        unless new_rpm.kind_of?(RPMDbPackage)
          raise ArgumentError, "Expecting an RPMDbPackage object"
        end

        @rpms[new_rpm.n] ||= Array.new

        # we may already have this one, like when the installed list is refreshed
        idx = @index[new_rpm.nevra]
        if idx
          # grab the existing package if it's not
          curr_rpm = idx
        else
          @rpms[new_rpm.n] << new_rpm

          new_rpm.provides.each do |provide|
            @provides[provide.name] ||= Array.new
            @provides[provide.name] << new_rpm
          end

          curr_rpm = new_rpm
        end

        # Track the nevra -> RPMPackage association to avoid having to compare versions
        # with @rpms[new_rpm.n] on the next round
        @index[new_rpm.nevra] = curr_rpm

        # these are overwritten for existing packages
        if new_rpm.available
          @available << curr_rpm
        end
        if new_rpm.installed
          @installed << curr_rpm
        end
      end
    end

size() click to toggle source

    # File lib/chef/provider/package/yum.rb, line 604
    def size
      @rpms.size
    end

Also aliased as: length
whatprovides(rpmdep) click to toggle source

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

      what = []

      packages = lookup_provides(rpmdep.name)
      if packages
        packages.each do |pkg|
          pkg.provides.each do |provide|
            if provide.satisfy?(rpmdep)
              what << pkg
            end
          end
        end
      end

      return what
    end