Class: Specinfra::Command::Darwin::Base::Package

Inherits:
Base::Package show all
Defined in:
lib/specinfra/command/darwin/base/package.rb

Class Method Summary collapse

Methods inherited from Base::Package

check_is_installed_by_cpan, check_is_installed_by_gem, check_is_installed_by_npm, check_is_installed_by_pear, check_is_installed_by_pecl, check_is_installed_by_pip, check_is_installed_by_pip2, check_is_installed_by_pip3, check_is_installed_by_rvm, check_is_installed_by_td_agent_gem

Methods inherited from Base

create, escape

Class Method Details

.brew_cask_listObject



49
50
51
52
53
# File 'lib/specinfra/command/darwin/base/package.rb', line 49

def brew_cask_list
  # Since `brew cask list` is slow, directly check Caskroom directory
  # Brew cask can install in multiple directories
  "ls -1 /opt/homebrew-cask/Caskroom/ /usr/local/Caskroom"
end

.brew_listObject



44
45
46
47
# File 'lib/specinfra/command/darwin/base/package.rb', line 44

def brew_list
  # Since `brew list` is slow, directly check Cellar directory
  'ls -1 "$(brew --prefix)/Cellar/"'
end

.check_is_installed(package, version = nil) ⇒ Object Also known as: check_is_installed_by_homebrew



3
4
5
6
7
8
9
10
11
# File 'lib/specinfra/command/darwin/base/package.rb', line 3

def check_is_installed(package, version=nil)
  escaped_package = escape(::File.basename(package))
  if version
    cmd = %Q[brew info #{escaped_package} | grep -E "^$(brew --prefix)/Cellar/#{escaped_package}/#{escape(version)}"]
  else
    cmd = "#{brew_list} | grep -E '^#{escaped_package}$'"
  end
  cmd
end

.check_is_installed_by_homebrew_cask(package, version = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/specinfra/command/darwin/base/package.rb', line 15

def check_is_installed_by_homebrew_cask(package, version=nil)
  escaped_package = escape(::File.basename(package))
  if version
    cmd = "brew cask info #{escaped_package} | grep -E '^/opt/homebrew-cask/Caskroom/#{escaped_package}/#{escape(version)}'"
  else
    cmd = "#{brew_cask_list} | grep -E '^#{escaped_package}$'"
  end
  cmd
end

.check_is_installed_by_pkgutil(package, version = nil) ⇒ Object



25
26
27
28
29
# File 'lib/specinfra/command/darwin/base/package.rb', line 25

def check_is_installed_by_pkgutil(package, version=nil)
  cmd = "pkgutil --pkg-info #{package}"
  cmd = "#{cmd} | grep '^version: #{escape(version)}'" if version
  cmd
end

.get_version(package, opts = nil) ⇒ Object



40
41
42
# File 'lib/specinfra/command/darwin/base/package.rb', line 40

def get_version(package, opts=nil)
  %Q[ls -1 "$(brew --prefix)/Cellar/#{package}/" | tail -1]
end

.install(package, version = nil, option = '') ⇒ Object



31
32
33
34
# File 'lib/specinfra/command/darwin/base/package.rb', line 31

def install(package, version=nil, option='')
  # Homebrew doesn't support to install specific version.
  cmd = "brew install #{option} '#{package}'"
end

.remove(package, option = '') ⇒ Object



36
37
38
# File 'lib/specinfra/command/darwin/base/package.rb', line 36

def remove(package, option='')
  cmd = "brew uninstall #{option} '#{package}'"
end