Sha256: 4f2da3d79ec27758094e7fc780847477f7039fcd2629e59c45312a4fbe6f9148
Contents?: true
Size: 949 Bytes
Versions: 69
Compression:
Stored size: 949 Bytes
Contents
# frozen_string_literal: true require 'eac_ruby_utils/configs/base' require 'yaml' module EacRubyUtils class Configs class File < ::EacRubyUtils::Configs::Base attr_reader :path, :options # Valid options: [:autosave] def initialize(path, options = {}) @path = path @options = options.to_sym_keys_hash.freeze super(raw_data_from_file) end def save ::FileUtils.mkdir_p(::File.dirname(path)) ::File.write(path, data.to_h.to_yaml) end def load replace(raw_data_from_file) end def write(entry_key, entry_value) super save if autosave? end def autosave? options[:autosave] ? true : false end private def raw_data_from_file if ::File.exist?(path) && ::File.size(path).positive? ::YAML.load_file(path) else {} end end end end end
Version data entries
69 entries across 69 versions & 3 rubygems