Class: Wright::Resource::Symlink

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

Overview

Symlink resource, represents a symlink.

Examples:

link = Wright::Resource::Symlink.new('/tmp/fstab')
link.to = '/etc/fstab'
link.create

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) ⇒ Symlink

Initializes a Symlink.

Parameters:

  • name (String)

    the symlink’s name



16
17
18
19
20
# File 'lib/wright/resource/symlink.rb', line 16

def initialize(name)
  super
  @to = nil
  @action = :create
end

Instance Attribute Details

#toString

Returns the symlink’s intended target.

Returns:

  • (String)

    the symlink’s intended target



23
24
25
# File 'lib/wright/resource/symlink.rb', line 23

def to
  @to
end

Instance Method Details

#createBool

Creates or updates the symlink.

Returns:

  • (Bool)

    true if the symlink was updated and false otherwise



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

def create
  fail ArgumentError, 'Symlink target undefined' unless @to
  might_update_resource do
    @provider.create
  end
end

#removeBool

Removes the symlink.

Returns:

  • (Bool)

    true if the symlink was updated and false otherwise



40
41
42
43
44
# File 'lib/wright/resource/symlink.rb', line 40

def remove
  might_update_resource do
    @provider.remove
  end
end