Sha256: 5461e1b2a47cbdf00ec235fefe28372ed1395ff6bdd7e4f4ae29f1c19900f507

Contents?: true

Size: 1.78 KB

Versions: 21

Compression:

Stored size: 1.78 KB

Contents

class Specinfra::Command::Darwin::Base::Package < Specinfra::Command::Base::Package
  class << self
    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

    alias :check_is_installed_by_homebrew :check_is_installed

    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

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

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

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

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

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

    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
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
specinfra-2.91.0 lib/specinfra/command/darwin/base/package.rb
specinfra-2.90.1 lib/specinfra/command/darwin/base/package.rb
specinfra-2.90.0 lib/specinfra/command/darwin/base/package.rb
specinfra-2.89.0 lib/specinfra/command/darwin/base/package.rb
specinfra-2.88.2 lib/specinfra/command/darwin/base/package.rb
specinfra-2.88.1 lib/specinfra/command/darwin/base/package.rb
specinfra-2.88.0 lib/specinfra/command/darwin/base/package.rb
specinfra-2.87.2 lib/specinfra/command/darwin/base/package.rb
specinfra-2.87.1 lib/specinfra/command/darwin/base/package.rb
specinfra-2.87.0 lib/specinfra/command/darwin/base/package.rb
specinfra-2.86.0 lib/specinfra/command/darwin/base/package.rb
specinfra-2.85.1 lib/specinfra/command/darwin/base/package.rb
specinfra-2.85.0 lib/specinfra/command/darwin/base/package.rb
specinfra-2.84.1 lib/specinfra/command/darwin/base/package.rb
specinfra-2.84.0 lib/specinfra/command/darwin/base/package.rb
specinfra-2.83.4 lib/specinfra/command/darwin/base/package.rb
specinfra-2.83.3 lib/specinfra/command/darwin/base/package.rb
specinfra-2.83.2 lib/specinfra/command/darwin/base/package.rb
specinfra-2.83.1 lib/specinfra/command/darwin/base/package.rb
specinfra-2.83.0 lib/specinfra/command/darwin/base/package.rb