Sha256: d5b225d31c759c73d7f37769f72cd18493ce73e6eea67aae675b150dbcc9135e
Contents?: true
Size: 1.55 KB
Versions: 127
Compression:
Stored size: 1.55 KB
Contents
# frozen_string_literal: true require 'active_support/core_ext/string' require 'yaml' require 'eac_ruby_utils/configs/file' require 'eac_ruby_utils/patches/hash/sym_keys_hash' require 'eac_ruby_utils/paths_hash' require 'eac_ruby_utils/simple_cache' module EacRubyUtils class Configs include ::EacRubyUtils::SimpleCache attr_reader :configs_key, :options # Valid options: [:storage_path] def initialize(configs_key, options = {}) @configs_key = configs_key @options = options.to_sym_keys_hash.freeze load end delegate :clear, to: :file delegate :save, to: :file delegate :load, to: :file def []=(entry_key, entry_value) write_entry(entry_key, entry_value) end def write_entry(entry_key, entry_value) file.write(entry_key, entry_value) end def [](entry_key) read_entry(entry_key) end def read_entry(entry_key) file.read(entry_key) end delegate :autosave?, to: :file private attr_accessor :data def file_uncached ::EacRubyUtils::Configs::File.new( storage_path, options ) end def storage_path_uncached path = options_storage_path || default_storage_path return path if ::File.exist?(path) && ::File.size(path).positive? ::FileUtils.mkdir_p(::File.dirname(path)) ::File.write(path, {}.to_yaml) path end def options_storage_path options[:storage_path] end def default_storage_path ::File.join(ENV['HOME'], '.config', configs_key, 'settings.yml') end end end
Version data entries
127 entries across 127 versions & 3 rubygems