Class: Wright::Provider::Package

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

Overview

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

Direct Known Subclasses

Apt, Homebrew, Yum

Defined Under Namespace

Classes: Apt, Homebrew, Yum

Constant Summary

Constants inherited from Wright::Provider

PROVIDER_DIR

Instance Method Summary collapse

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

#installvoid

This method returns an undefined value.

Installs the package.


11
12
13
14
15
16
17
18
# 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

#install_packageObject (private)


81
82
83
# File 'lib/wright/provider/package.rb', line 81

def install_package
  fail NotImplementedError
end

#installed?Bool

Returns true if the package is installed, false otherwise.

Returns:

  • (Bool)

    true if the package is installed, false otherwise


39
40
41
42
43
44
45
# 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_versionsArray<String>

Returns the installed package versions.

Returns:

  • (Array<String>)

    the installed package versions


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

def installed_versions
  fail NotImplementedError
end

#package_nameObject (private)


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

def package_name
  @resource.name
end

#package_optionsObject (private)


57
58
59
# File 'lib/wright/provider/package.rb', line 57

def package_options
  @resource.options
end

#package_versionObject (private)


53
54
55
# File 'lib/wright/provider/package.rb', line 53

def package_version
  @resource.version
end

#removevoid

This method returns an undefined value.

Removes the package.


23
24
25
26
27
28
29
30
# 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

#remove_packageObject (private)


85
86
87
# File 'lib/wright/provider/package.rb', line 85

def remove_package
  fail NotImplementedError
end

#uptodate?(action) ⇒ Bool (private)

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

Parameters:

  • action (Symbol)

    the action. Currently supports :install and :remove.

Returns:

  • (Bool)

    true if the package is up-to-date and false otherwise

Raises:

  • (ArgumentError)

    if the action is invalid


70
71
72
73
74
75
76
77
78
79
# 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