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

#run_action

Constructor Details

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

Initializes a File.

Parameters:

  • name (String)

    the file's name

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

    the arguments

Options Hash (args):

  • :action (Symbol) — default: :create

    the action

  • :content (String, #to_s)

    the file's content

  • :mode (String, Integer)

    the file's mode

  • :owner (String, Integer)

    the file's owner

  • :group (String, Integer)

    the file's group


46
47
48
49
50
51
52
53
54
# File 'lib/wright/resource/file.rb', line 46

def initialize(name, args = {})
  super
  @action     = args.fetch(:action, :create)
  @content    = args.fetch(:content, nil)
  @mode       = args.fetch(:mode, nil)
  owner       = args.fetch(:owner, nil)
  group       = args.fetch(:group, nil)
  @file_owner = Wright::Util::FileOwner.new(owner, group)
end

Instance Attribute Details

#contentString, #to_s

Returns the file's intended content.

Returns:

  • (String, #to_s)

    the file's intended content


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

def content
  @content
end

#groupString, Integer

Returns the directory's intended group.

Returns:

  • (String, Integer)

    the directory's intended group


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

def_delegator :file_owner, :group=

#modeString, Integer

Returns the file's intended mode.

Returns:

  • (String, Integer)

    the file's intended mode


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

def mode
  @mode
end

#ownerString, Integer

Returns the directory's intended owner.

Returns:

  • (String, Integer)

    the directory's intended owner


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

def_delegator :file_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


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

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


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

def remove
  might_update_resource do
    provider.remove
  end
end