Class: Wright::Resource::Package

Inherits:
Wright::Resource show all
Extended by:
Forwardable
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

#run_action

Constructor Details

#initialize(name, args = {}) ⇒ Package

Initializes a Package.

Parameters:

  • name (String)

    the package’s name

  • args (Hash) (defaults to: {})

    the arguments

Options Hash (args):

  • :action (Symbol) — default: :install

    the action

  • :version (String, #to_s)

    the package version

  • :options (String, Array<String>)

    the package options



41
42
43
44
45
46
# File 'lib/wright/resource/package.rb', line 41

def initialize(name, args = {})
  super
  @action  = args.fetch(:action, :install)
  @version = args.fetch(:version, nil)
  @options = args.fetch(:options, nil)
end

Instance Attribute Details

#optionsString+

Returns the options passed to the package manager.

Returns:

  • (String, Array<String>)

    the options passed to the package manager



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

def options
  @options
end

#versionString

Returns the package version to install or remove.

Returns:

  • (String)

    the package version to install or remove



28
29
30
# File 'lib/wright/resource/package.rb', line 28

def version
  @version
end

Instance Method Details

#installBool

Installs the Package.

Returns:

  • (Bool)

    true if the package was updated and false otherwise



60
61
62
63
64
# File 'lib/wright/resource/package.rb', line 60

def install
  might_update_resource do
    provider.install
  end
end

#installed?Bool

Returns true if the package is installed.

Returns:

  • (Bool)

    true if the package is installed



54
# File 'lib/wright/resource/package.rb', line 54

def_delegator :provider, :installed?

#installed_versionsArray<String>

Returns the installed package versions.

Returns:

  • (Array<String>)

    the installed package versions



50
# File 'lib/wright/resource/package.rb', line 50

def_delegator :provider, :installed_versions

#removeBool Also known as: uninstall

Removes the Package.

Returns:

  • (Bool)

    true if the package was updated and false otherwise



70
71
72
73
74
# File 'lib/wright/resource/package.rb', line 70

def remove
  might_update_resource do
    provider.remove
  end
end