Class: Wright::Resource::Directory

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

Overview

Directory resource, represents a directory.

Examples:

dir = Wright::Resource::Directory.new('/tmp/foobar')
dir.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 = {}) ⇒ Directory

Initializes a Directory.

Parameters:

  • name (String)

    the directory’s name

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

    the arguments

Options Hash (args):

  • :action (Symbol) — default: :create

    the action

  • :mode (String, Integer)

    the directory’s mode

  • :owner (String, Integer)

    the directory’s owner

  • :group (String, Integer)

    the directory’s group



25
26
27
28
29
30
31
32
# File 'lib/wright/resource/directory.rb', line 25

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

Instance Attribute Details

#groupString, Integer

Returns the directory’s intended group.

Returns:

  • (String, Integer)

    the directory’s intended group



48
# File 'lib/wright/resource/directory.rb', line 48

def_delegator :dir_owner, :group

#modeString, Integer

Returns the directory’s intended mode.

Returns:

  • (String, Integer)

    the directory’s intended mode



35
36
37
# File 'lib/wright/resource/directory.rb', line 35

def mode
  @mode
end

#ownerString, Integer

Returns the directory’s intended owner.

Returns:

  • (String, Integer)

    the directory’s intended owner



41
# File 'lib/wright/resource/directory.rb', line 41

def_delegator :dir_owner, :user_and_group=, :owner=

Instance Method Details

#createBool

Creates or updates the directory.

Returns:

  • (Bool)

    true if the directory was updated and false otherwise



55
56
57
58
59
# File 'lib/wright/resource/directory.rb', line 55

def create
  might_update_resource do
    provider.create
  end
end

#removeBool

Removes the directory.

Returns:

  • (Bool)

    true if the directory was updated and false otherwise



65
66
67
68
69
# File 'lib/wright/resource/directory.rb', line 65

def remove
  might_update_resource do
    provider.remove
  end
end