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', 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

#run_action

Constructor Details

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

Initializes a Symlink.

Parameters:

  • name (String)

    the symlink’s name

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

    the arguments

Options Hash (args):

  • :action (Symbol) — default: :create

    the action

  • :to (String)

    the symlink’s target



18
19
20
21
22
# File 'lib/wright/resource/symlink.rb', line 18

def initialize(name, args = {})
  super
  @action = args.fetch(:action, :create)
  @to     = args.fetch(:to, nil)
end

Instance Attribute Details

#toString

Returns the symlink’s intended target.

Returns:

  • (String)

    the symlink’s intended target



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

def to
  @to
end

Instance Method Details

#createBool

Creates or updates the symlink.

Returns:

  • (Bool)

    true if the symlink was updated and false otherwise



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

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



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

def remove
  might_update_resource do
    provider.remove
  end
end