Class: Package
- Inherits:
-
Object
- Object
- Package
- Defined in:
- lib/resources/package.rb
Overview
Resource to determine package information
Usage: describe package(‘nginx’) do
it { should be_installed }
end
Instance Method Summary collapse
-
#info ⇒ Object
returns the package description.
-
#initialize(package_name = nil) ⇒ Package
constructor
A new instance of Package.
-
#installed?(_provider = nil, _version = nil) ⇒ Boolean
returns true if the package is installed.
- #to_s ⇒ Object
-
#version ⇒ Object
return the package version.
Constructor Details
#initialize(package_name = nil) ⇒ Package
Returns a new instance of Package.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/resources/package.rb', line 21 def initialize(package_name = nil) @package_name = package_name @name = @package_name @cache = nil # select package manager @pkgman = nil case inspec.os[:family] when 'ubuntu', 'debian' @pkgman = Deb.new(inspec) when 'redhat', 'fedora', 'centos', 'opensuse', 'wrlinux' @pkgman = Rpm.new(inspec) when 'arch' @pkgman = Pacman.new(inspec) when 'darwin' @pkgman = Brew.new(inspec) when 'windows' @pkgman = WindowsPkg.new(inspec) when 'aix' @pkgman = BffPkg.new(inspec) else return skip_resource 'The `package` resource is not supported on your OS yet.' end end |
Instance Method Details
#info ⇒ Object
returns the package description
53 54 55 56 57 |
# File 'lib/resources/package.rb', line 53 def info return @cache if !@cache.nil? return nil if @pkgman.nil? @pkgman.info(@package_name) end |
#installed?(_provider = nil, _version = nil) ⇒ Boolean
returns true if the package is installed
47 48 49 50 |
# File 'lib/resources/package.rb', line 47 def installed?(_provider = nil, _version = nil) return false if info.nil? info[:installed] == true end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/resources/package.rb', line 66 def to_s "System Package #{@package_name}" end |
#version ⇒ Object
return the package version
60 61 62 63 64 |
# File 'lib/resources/package.rb', line 60 def version info = @pkgman.info(@package_name) return nil if info.nil? info[:version] end |