Class: Wright::Provider::File

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

Overview

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

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 file.

Raises:

  • (Errno::EISDIR)

    if there already is a directory with the specified name



19
20
21
22
23
24
25
26
27
28
# File 'lib/wright/provider/file.rb', line 19

def create
  fail_if_directory
  file_permissions = permissions
  unless_uptodate(:create, "file already created: '#{file_name}'") do
    unless_dry_run("create file: '#{file_name}'") do
      write_content_to_file
      file_permissions.update unless file_permissions.uptodate?
    end
  end
end

#removevoid

This method returns an undefined value.

Removes the file.

Raises:

  • (Errno::EISDIR)

    if there is a directory with the specified name



35
36
37
38
39
40
41
42
# File 'lib/wright/provider/file.rb', line 35

def remove
  fail_if_directory
  unless_uptodate(:remove, "file already removed: '#{file_name}'") do
    unless_dry_run("remove file: '#{file_name}'") do
      FileUtils.rm(filename_expanded)
    end
  end
end