Class: CemAcpt::Utils::Files::JsonUtil
- Defined in:
- lib/cem_acpt/utils/files.rb
Overview
Utility class for working with JSON files
Constant Summary collapse
- VALID_EXTS =
%w[.json].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 JSON file %s...', **_kwargs) ⇒ Object
-
#initialize(log_level: :debug, log_prefix: 'CemAcpt', file_exts: VALID_EXTS) ⇒ JsonUtil
constructor
A new instance of JsonUtil.
- #read(file, *_args, log_msg: 'Reading JSON file %s...', **_kwargs) ⇒ Object
- #write(file, content, *_args, log_msg: 'Writing JSON 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) ⇒ JsonUtil
Returns a new instance of JsonUtil.
168 169 170 171 |
# File 'lib/cem_acpt/utils/files.rb', line 168 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 'json' end |
Instance Method Details
#delete(file, *_args, log_msg: 'Deleting JSON file %s...', **_kwargs) ⇒ Object
183 184 185 |
# File 'lib/cem_acpt/utils/files.rb', line 183 def delete(file, *_args, log_msg: 'Deleting JSON file %s...', **_kwargs) super(file, log_msg) end |
#read(file, *_args, log_msg: 'Reading JSON file %s...', **_kwargs) ⇒ Object
179 180 181 |
# File 'lib/cem_acpt/utils/files.rb', line 179 def read(file, *_args, log_msg: 'Reading JSON file %s...', **_kwargs) JSON.parse(super(file, log_msg)) end |
#write(file, content, *_args, log_msg: 'Writing JSON file %s...', **_kwargs) ⇒ Object
173 174 175 176 177 |
# File 'lib/cem_acpt/utils/files.rb', line 173 def write(file, content, *_args, log_msg: 'Writing JSON file %s...', **_kwargs) raise ArgumentError, 'content must be a Hash' unless content.is_a?(Hash) super(file, content.to_json, log_msg) end |