class Wright::Provider::Package

Package provider. Used as a base class for Resource::Package providers.

Public Instance Methods

install() click to toggle source

Installs the package.

@return [void]

# File lib/wright/provider/package.rb, line 11
def install
  unless_uptodate(:install,
                  "package already installed: '#{package_name}'") do
    unless_dry_run("install package: '#{package_name}'") do
      install_package
    end
  end
end
installed?() click to toggle source

@return [Bool] true if the package is installed, false

otherwise
# File lib/wright/provider/package.rb, line 39
def installed?
  if package_version
    installed_versions.include?(package_version)
  else
    !installed_versions.empty?
  end
end
installed_versions() click to toggle source

@return [Array<String>] the installed package versions

# File lib/wright/provider/package.rb, line 33
def installed_versions
  fail NotImplementedError
end
remove() click to toggle source

Removes the package.

@return [void]

# File lib/wright/provider/package.rb, line 23
def remove
  unless_uptodate(:remove,
                  "package already removed: '#{package_name}'") do
    unless_dry_run("remove package: '#{package_name}'") do
      remove_package
    end
  end
end

Private Instance Methods

install_package() click to toggle source
# File lib/wright/provider/package.rb, line 81
def install_package
  fail NotImplementedError
end
package_name() click to toggle source
# File lib/wright/provider/package.rb, line 49
def package_name
  resource.name
end
package_options() click to toggle source
# File lib/wright/provider/package.rb, line 57
def package_options
  resource.options
end
package_version() click to toggle source
# File lib/wright/provider/package.rb, line 53
def package_version
  resource.version
end
remove_package() click to toggle source
# File lib/wright/provider/package.rb, line 85
def remove_package
  fail NotImplementedError
end
uptodate?(action) click to toggle source

@api public Checks if the package is up-to-date for a given action.

@param action [Symbol] the action. Currently supports

+:install+ and +:remove+.

@return [Bool] true if the package is up-to-date and false

otherwise

@raise [ArgumentError] if the action is invalid

# File lib/wright/provider/package.rb, line 70
def uptodate?(action)
  case action
  when :install
    installed?
  when :remove
    !installed?
  else
    fail ArgumentError, "invalid action '#{action}'"
  end
end