Class: Wright::Provider::Package::Homebrew

Inherits:
Wright::Provider::Package show all
Defined in:
lib/wright/provider/package/homebrew.rb

Overview

Homebrew package provider. Used as a provider for Resource::Package on OS X systems.

Constant Summary

Constants inherited from Wright::Provider

Wright::Provider::PROVIDER_DIR

Instance Method Summary collapse

Methods inherited from Wright::Provider::Package

#install, #installed?, #package_name, #package_options, #package_version, #remove, #uptodate?

Methods inherited from Wright::Provider

#env, #exec_or_fail, #initialize, #unless_dry_run, #unless_uptodate, #updated?

Constructor Details

This class inherits a constructor from Wright::Provider

Instance Method Details

#brew(action, package, version = nil) ⇒ Object (private)


38
39
40
41
42
43
44
45
46
# File 'lib/wright/provider/package/homebrew.rb', line 38

def brew(action, package, version = nil)
  ignore_version(version)

  Wright::Util.bundler_clean_env do
    error_message = "cannot #{action} package '#{package}'"
    args = [action.to_s, *package_options, package]
    exec_or_fail('brew', args, error_message)
  end
end

#ignore_version(version) ⇒ Object (private)


48
49
50
51
52
# File 'lib/wright/provider/package/homebrew.rb', line 48

def ignore_version(version)
  return unless version
  package_info = "#{package_name} (#{version})"
  Wright.log.warn "ignoring package version: '#{package_info}'"
end

#install_packageObject (private)


30
31
32
# File 'lib/wright/provider/package/homebrew.rb', line 30

def install_package
  brew(:install, package_name, package_version)
end

#installed_versionsArray<String>

Returns the installed package versions.

Returns:

  • (Array<String>)

    the installed package versions


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wright/provider/package/homebrew.rb', line 14

def installed_versions
  cmd = 'brew'
  args = ['info', '--json=v1', package_name]
  cmd_stdout, _, cmd_status = Wright::Util.bundler_clean_env do
    Open3.capture3(env, cmd, *args)
  end

  if cmd_status.success?
    JSON[cmd_stdout].first['installed'].map { |v| v['version'] }
  else
    []
  end
end

#remove_packageObject (private)


34
35
36
# File 'lib/wright/provider/package/homebrew.rb', line 34

def remove_package
  brew(:uninstall, package_name)
end