Class: Wright::Provider::Directory

Inherits:
Wright::Provider show all
Defined in:
lib/wright/provider/directory.rb

Overview

Directory provider. Used as a provider for Resource::Directory.

Constant Summary

Constants inherited from Wright::Provider

PROVIDER_DIR

Instance Method Summary collapse

Methods inherited from Wright::Provider

#initialize, #updated?

Constructor Details

This class inherits a constructor from Wright::Provider

Instance Method Details

#createvoid

This method returns an undefined value.

Creates or updates the directory.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/wright/provider/directory.rb', line 14

def create
  fail Errno::EEXIST, dirname_expanded if regular_file?

  dir_permissions = permissions
  unless_uptodate(:create, "directory already created: '#{dir_name}'") do
    unless_dry_run("create directory: '#{dir_name}'") do
      FileUtils.mkdir_p(dirname_expanded)
      dir_permissions.update unless dir_permissions.uptodate?
    end
  end
end

#removevoid

This method returns an undefined value.

Removes the directory.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/wright/provider/directory.rb', line 29

def remove
  if ::File.exist?(dirname_expanded) &&
     !::File.directory?(dirname_expanded)
    fail "'#{dirname_expanded}' exists but is not a directory"
  end

  unless_uptodate(:remove, "directory already removed: '#{dir_name}'") do
    unless_dry_run("remove directory: '#{dir_name}'") do
      FileUtils.rmdir(dirname_expanded)
    end
  end
end