Class: Inspec::Resources::Package
- Inherits:
-
Object
- Object
- Inspec::Resources::Package
- Defined in:
- lib/resources/package.rb
Instance Method Summary collapse
-
#info ⇒ Object
returns the package description.
-
#initialize(package_name = nil) ⇒ Package
constructor
rubocop:disable Metrics/AbcSize.
-
#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
rubocop:disable Metrics/AbcSize
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/resources/package.rb', line 22 def initialize(package_name = nil) # rubocop:disable Metrics/AbcSize @package_name = package_name @name = @package_name @cache = nil # select package manager @pkgman = nil os = inspec.os if os.debian? @pkgman = Deb.new(inspec) elsif os.redhat? || os.suse? @pkgman = Rpm.new(inspec) elsif ['arch'].include?(os[:family]) @pkgman = Pacman.new(inspec) elsif ['darwin'].include?(os[:family]) @pkgman = Brew.new(inspec) elsif inspec.os.windows? @pkgman = WindowsPkg.new(inspec) elsif ['aix'].include?(os[:family]) @pkgman = BffPkg.new(inspec) elsif os.solaris? @pkgman = SolarisPkg.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
56 57 58 59 60 |
# File 'lib/resources/package.rb', line 56 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
50 51 52 53 |
# File 'lib/resources/package.rb', line 50 def installed?(_provider = nil, _version = nil) return false if info.nil? info[:installed] == true end |
#to_s ⇒ Object
69 70 71 |
# File 'lib/resources/package.rb', line 69 def to_s "System Package #{@package_name}" end |
#version ⇒ Object
return the package version
63 64 65 66 67 |
# File 'lib/resources/package.rb', line 63 def version info = @pkgman.info(@package_name) return nil if info.nil? info[:version] end |