Class: CemAcpt::Utils::Files::YamlUtil
- Defined in:
- lib/cem_acpt/utils/files.rb
Overview
Utility class for working with YAML files
Constant Summary collapse
- VALID_EXTS =
%w[.yaml .yml].freeze
- DEFAULT_PERMITTED_CLASSES =
[Symbol].freeze
Constants included from Logging
Instance Attribute Summary
Attributes inherited from FileUtil
#file_exts, #log_level, #log_prefix
Instance Method Summary collapse
- #delete(file, *_args, log_msg: 'Deleting YAML file %s...', **_kwargs) ⇒ Object
-
#initialize(log_level: :debug, log_prefix: 'CemAcpt', file_exts: VALID_EXTS) ⇒ YamlUtil
constructor
A new instance of YamlUtil.
- #read(file, *_args, log_msg: 'Reading YAML file %s...', permitted_classes: DEFAULT_PERMITTED_CLASSES, **_kwargs) ⇒ Object
- #write(file, content, *_args, log_msg: 'Writing YAML file %s...', **_kwargs) ⇒ Object
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: VALID_EXTS) ⇒ YamlUtil
Returns a new instance of YamlUtil.
144 145 146 147 |
# File 'lib/cem_acpt/utils/files.rb', line 144 def initialize(log_level: :debug, log_prefix: 'CemAcpt', file_exts: VALID_EXTS) super(log_level: log_level, log_prefix: log_prefix, file_exts: file_exts) require 'yaml' end |
Instance Method Details
#delete(file, *_args, log_msg: 'Deleting YAML file %s...', **_kwargs) ⇒ Object
159 160 161 |
# File 'lib/cem_acpt/utils/files.rb', line 159 def delete(file, *_args, log_msg: 'Deleting YAML file %s...', **_kwargs) super(file, log_msg) end |
#read(file, *_args, log_msg: 'Reading YAML file %s...', permitted_classes: DEFAULT_PERMITTED_CLASSES, **_kwargs) ⇒ Object
155 156 157 |
# File 'lib/cem_acpt/utils/files.rb', line 155 def read(file, *_args, log_msg: 'Reading YAML file %s...', permitted_classes: DEFAULT_PERMITTED_CLASSES, **_kwargs) YAML.safe_load(super(file, log_msg), permitted_classes: permitted_classes) end |
#write(file, content, *_args, log_msg: 'Writing YAML file %s...', **_kwargs) ⇒ Object
149 150 151 152 153 |
# File 'lib/cem_acpt/utils/files.rb', line 149 def write(file, content, *_args, log_msg: 'Writing YAML file %s...', **_kwargs) raise ArgumentError, 'content must be a Hash' unless content.is_a?(Hash) super(file, content.to_yaml, log_msg) end |