Class: Wright::Resource::Package

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

Overview

Public: 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

Public: Initialize a Package.

name - The package name.



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

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

Instance Attribute Details

#versionObject

Public: Get/Set the package version to install/remove.



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

def version
  @version
end

Instance Method Details

#installObject

Public: Install the Package.

Returns true if the package was updated and false otherwise.



46
47
48
49
50
# File 'lib/wright/resource/package.rb', line 46

def install
  might_update_resource do
    @provider.install
  end
end

#installed_versionsObject

Public: Get the installed version of a package.

Returns an array of installed package version Strings.



39
40
41
# File 'lib/wright/resource/package.rb', line 39

def installed_versions
  @provider.installed_versions
end

#removeObject

Public: Remove the Package.

Returns true if the package was updated and false otherwise.



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

def remove
  might_update_resource do
    @provider.remove
  end
end