Sha256: 82d0def6b7c27767eeab58d1758501010529b44687d0b9be3803d9e9d0ce47a4

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

require 'open3'

require 'wright/provider'
require 'wright/provider/package'

module Wright
  class Provider
    class Package
      # Yum package provider. Used as a provider for
      # {Resource::Package} on Fedora-based systems.
      class Yum < Wright::Provider::Package
        # @return [Array<String>] the installed package versions
        def installed_versions
          version_format = '%{VERSION}-%{RELEASE}'
          rpm_args = %W(-q #{package_name} --qf #{version_format})
          stdout, _, status = Open3.capture3(env, 'rpm', *rpm_args)
          status.success? ? [stdout] : []
        end

        private

        def install_package
          yum(:install, package_options, package_name, package_version)
        end

        def remove_package
          yum(:remove, package_options, package_name)
        end

        def yum(action, options, package, version = nil)
          cmd = 'yum'
          package_version = version.nil? ? '' : "-#{version}"
          args = ['-y', *options, action.to_s, package + package_version]
          exec_or_fail(cmd, args, "cannot #{action} package '#{package}'")
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wright-0.5.0 lib/wright/provider/package/yum.rb