Module: CemAcpt::Utils::Files

Defined in:
lib/cem_acpt/utils/files.rb

Overview

Utility classes and methods for files

Defined Under Namespace

Classes: FileUtil, JsonUtil, YamlUtil

Class Method Summary collapse

Class Method Details

.delete(file, *args, log_level: :debug, log_prefix: 'CemAcpt', **kwargs) ⇒ Object



31
32
33
# File 'lib/cem_acpt/utils/files.rb', line 31

def delete(file, *args, log_level: :debug, log_prefix: 'CemAcpt', **kwargs)
  new_file_util_for(file, log_level: log_level, log_prefix: log_prefix).delete(file, *args, **kwargs)
end

.read(file, *args, log_level: :debug, log_prefix: 'CemAcpt', **kwargs) ⇒ Object

Reads a file based on its extension

Parameters:

  • file (String)

    Path to the file

  • log_level (Symbol) (defaults to: :debug)

    Log level to use

  • log_prefix (String) (defaults to: 'CemAcpt')

    Log prefix to use

  • kwargs (Hash)

    Keyword arguments to pass to the file utility

Options Hash (**kwargs):

  • :log_msg (String)

    Log message to use when logging the file operation

  • :permitted_classes (Array)

    Array of classes to permit when loading YAML files

Returns:

  • (Object)

    The result of the file utility’s read method



19
20
21
22
23
24
25
# File 'lib/cem_acpt/utils/files.rb', line 19

def read(file, *args, log_level: :debug, log_prefix: 'CemAcpt', **kwargs)
  return from_content_registry(file, :content) unless file_changed?(file)

  content = new_file_util_for(file, log_level: log_level, log_prefix: log_prefix).read(file, *args, **kwargs)
  add_to_content_registry(file, :content, content)
  content
end

.write(file, content, *args, log_level: :debug, log_prefix: 'CemAcpt', **kwargs) ⇒ Object



27
28
29
# File 'lib/cem_acpt/utils/files.rb', line 27

def write(file, content, *args, log_level: :debug, log_prefix: 'CemAcpt', **kwargs)
  new_file_util_for(file, log_level: log_level, log_prefix: log_prefix).write(file, content, *args, **kwargs)
end