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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/resources/package.rb', line 14 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' @pkgman = Rpm.new(inspec) when 'arch' @pkgman = Pacman.new(inspec) when 'darwin' @pkgman = Brew.new(inspec) when 'windows' @pkgman = WindowsPkg.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
44 45 46 47 48 |
# File 'lib/resources/package.rb', line 44 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
38 39 40 41 |
# File 'lib/resources/package.rb', line 38 def installed?(_provider = nil, _version = nil) return false if info.nil? info[:installed] == true end |
#to_s ⇒ Object
57 58 59 |
# File 'lib/resources/package.rb', line 57 def to_s "System Package #{@package_name}" end |
#version ⇒ Object
return the package version
51 52 53 54 55 |
# File 'lib/resources/package.rb', line 51 def version info = @pkgman.info(@package_name) return nil if info.nil? info[:version] end |