Class: Inspec::Resources::Brew

Inherits:
PkgManagement show all
Defined in:
lib/resources/package.rb

Overview

MacOS / Darwin implementation

Instance Attribute Summary

Attributes inherited from PkgManagement

#inspec

Instance Method Summary collapse

Methods inherited from PkgManagement

#initialize, #missing_requirements

Constructor Details

This class inherits a constructor from Inspec::Resources::PkgManagement

Instance Method Details

#info(package_name) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/resources/package.rb', line 194

def info(package_name)
  brew_path = inspec.command('brew').exist? ? 'brew' : '/usr/local/bin/brew'
  cmd = inspec.command("#{brew_path} info --json=v1 #{package_name}")
  return {} if cmd.exit_status.to_i != 0
  # parse data
  pkg = JSON.parse(cmd.stdout)[0]
  {
    name: pkg['name'],
    installed: true,
    version: pkg['installed'][0]['version'],
    type: 'brew',
  }
rescue JSON::ParserError => e
  raise Inspec::Exceptions::ResourceFailed,
        'Failed to parse JSON from `brew` command. ' \
        "Error: #{e}"
end