Class: Wright::Resource::Package

Inherits:
Wright::Resource show all
Defined in:
lib/wright/resource/package.rb

Overview

Package resource, represents a package.

Examples:

vim = Wright::Resource::Package.new('vim')
vim.installed_versions
# => []
vim.install
vim.installed_versions
# => ["2:7.3.547-7"]

htop = Wright::Resource::Package.new('htop')
htop.installed_versions
# => ["1.0.1-1"]
htop.remove
htop.installed_versions
# => []

Instance Attribute Summary collapse

Attributes inherited from Wright::Resource

#action, #ignore_failure, #name, #resource_name

Instance Method Summary collapse

Methods inherited from Wright::Resource

#on_update=, #run_action

Constructor Details

#initialize(name) ⇒ Package

Initializes a Package.

Parameters:

  • name (String)

    the package’s name



29
30
31
32
33
# File 'lib/wright/resource/package.rb', line 29

def initialize(name)
  super
  @version = nil
  @action = :install
end

Instance Attribute Details

#versionString

Returns the package version to install or remove.

Returns:

  • (String)

    the package version to install or remove



24
25
26
# File 'lib/wright/resource/package.rb', line 24

def version
  @version
end

Instance Method Details

#installBool

Installs the Package.

Returns:

  • (Bool)

    true if the package was updated and false otherwise



44
45
46
47
48
# File 'lib/wright/resource/package.rb', line 44

def install
  might_update_resource do
    @provider.install
  end
end

#installed_versionsArray<String>

Returns the installed package versions.

Returns:

  • (Array<String>)

    the installed package versions



36
37
38
# File 'lib/wright/resource/package.rb', line 36

def installed_versions
  @provider.installed_versions
end

#removeBool Also known as: uninstall

Removes the Package.

Returns:

  • (Bool)

    true if the package was updated and false otherwise



54
55
56
57
58
# File 'lib/wright/resource/package.rb', line 54

def remove
  might_update_resource do
    @provider.remove
  end
end