Class: Wright::Resource::File

Inherits:
Wright::Resource show all
Extended by:
Forwardable
Defined in:
lib/wright/resource/file.rb

Overview

Symlink resource, represents a symlink.

Examples:

file = Wright::Resource::File.new('/tmp/foo')
file.content = 'bar'
file.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

#log_error, #might_update_resource, #on_update=, #provider_for_resource, #provider_name, #resource_class, #run_action, #run_update_action

Constructor Details

#initialize(name) ⇒ File

Initializes a File.

Parameters:

  • name (String)

    the file's name


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

def initialize(name)
  super
  @content = nil
  @mode = nil
  @owner = Wright::Util::FileOwner.new
  @action = :create
end

Instance Attribute Details

#contentString

Returns the file's intended content.

Returns:

  • (String)

    the file's intended content


19
20
21
# File 'lib/wright/resource/file.rb', line 19

def content
  @content
end

#groupString, Integer

Returns the directory's intended group.

Returns:

  • (String, Integer)

    the directory's intended group


35
# File 'lib/wright/resource/file.rb', line 35

def_delegator :@owner, :group=

#modeString, Integer

Returns the file's intended mode.

Returns:

  • (String, Integer)

    the file's intended mode


22
23
24
# File 'lib/wright/resource/file.rb', line 22

def mode
  @mode
end

#ownerString, Integer

Returns the directory's intended owner.

Returns:

  • (String, Integer)

    the directory's intended owner


28
# File 'lib/wright/resource/file.rb', line 28

def_delegator :@owner, :user_and_group=, :owner=

Instance Method Details

#createBool

Creates or updates the file.

Returns:

  • (Bool)

    true if the file was updated and false otherwise


53
54
55
56
57
# File 'lib/wright/resource/file.rb', line 53

def create
  might_update_resource do
    @provider.create
  end
end

#removeBool

Removes the file.

Returns:

  • (Bool)

    true if the file was updated and false otherwise


63
64
65
66
67
# File 'lib/wright/resource/file.rb', line 63

def remove
  might_update_resource do
    @provider.remove
  end
end