Class: Plat4m::Sniffer::Darwin::MacPkgManager::Homebrew

Inherits:
PkgManager
  • Object
show all
Defined in:
lib/plat4m/sniff/darwin.rb

Instance Method Summary collapse

Methods inherited from PkgManager

#has_sudo?, #install, #is_root?, #select_available, #select_uninstalled, #uninstall

Constructor Details

#initialize(owner) ⇒ Homebrew

Returns a new instance of Homebrew.



112
113
114
115
116
# File 'lib/plat4m/sniff/darwin.rb', line 112

def initialize(owner)
  super()
  @owner = owner
  @has_sudo = @owner.has_sudo?
end

Instance Method Details

#available?(pkg) ⇒ Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/plat4m/sniff/darwin.rb', line 123

def available?(pkg)
  system(%Q[brew search "/^#{pkg}$/" >/dev/null 2>&1])
end

#installed?(pkg) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
121
# File 'lib/plat4m/sniff/darwin.rb', line 118

def installed?(pkg)
  `brew list -1 --formula`.strip.split("\n").include?(pkg) ||
    `brew list -1 --cask`.strip.split("\n").include?(pkg)
end

#make_install_command(*pkgs) ⇒ Object



127
128
129
# File 'lib/plat4m/sniff/darwin.rb', line 127

def make_install_command(*pkgs)
  "brew install -q #{pkgs.join(' ')}"
end

#make_uninstall_command(*pkgs) ⇒ Object



131
132
133
# File 'lib/plat4m/sniff/darwin.rb', line 131

def make_uninstall_command(*pkgs)
  "brew uninstall -q #{pkgs.join(' ')}"
end