Class: CemAcpt::Utils::Files::FileUtil

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/cem_acpt/utils/files.rb

Overview

Generic file utility class

Direct Known Subclasses

JsonUtil, YamlUtil

Constant Summary

Constants included from Logging

Logging::LEVEL_MAP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

current_log_config, #current_log_config, current_log_format, #current_log_format, #current_log_level, current_log_level, included, #logger, logger, new_log_config, #new_log_config, new_log_formatter, #new_log_formatter, #new_log_level, new_log_level, #new_logger, new_logger, verbose?, #verbose?

Constructor Details

#initialize(log_level: :debug, log_prefix: 'CemAcpt', file_exts: []) ⇒ FileUtil

Returns a new instance of FileUtil.



86
87
88
89
90
# File 'lib/cem_acpt/utils/files.rb', line 86

def initialize(log_level: :debug, log_prefix: 'CemAcpt', file_exts: [])
  @log_level = log_level
  @log_prefix = log_prefix
  @file_exts = file_exts
end

Instance Attribute Details

#file_extsObject

Returns the value of attribute file_exts.



84
85
86
# File 'lib/cem_acpt/utils/files.rb', line 84

def file_exts
  @file_exts
end

#log_levelObject

Returns the value of attribute log_level.



84
85
86
# File 'lib/cem_acpt/utils/files.rb', line 84

def log_level
  @log_level
end

#log_prefixObject

Returns the value of attribute log_prefix.



84
85
86
# File 'lib/cem_acpt/utils/files.rb', line 84

def log_prefix
  @log_prefix
end

Instance Method Details

#delete(file, *_args, log_msg: 'Deleting file %s...', **_kwargs) ⇒ Object



119
120
121
122
# File 'lib/cem_acpt/utils/files.rb', line 119

def delete(file, *_args, log_msg: 'Deleting file %s...', **_kwargs)
  validate_and_log(file, log_msg)
  FileUtils.rm_f(file)
end

#read(file, *_args, log_msg: 'Reading file %s...', **_kwargs) ⇒ Object



114
115
116
117
# File 'lib/cem_acpt/utils/files.rb', line 114

def read(file, *_args, log_msg: 'Reading file %s...', **_kwargs)
  validate_and_log(file, log_msg)
  File.read(file)
end

#write(file, content, *_args, log_msg: 'Writing file %s...', **_kwargs) ⇒ Object



109
110
111
112
# File 'lib/cem_acpt/utils/files.rb', line 109

def write(file, content, *_args, log_msg: 'Writing file %s...', **_kwargs)
  validate_and_log(file, log_msg)
  File.write(file, content)
end