Sha256: c4cfddab23fb85c546b4e72ee9916885c02eb4fb3b8dd21fc09bb796c6dd1d0e

Contents?: true

Size: 1.6 KB

Versions: 185

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require 'active_support/core_ext/string'
require 'yaml'
require 'eac_config/old_configs/file'
require 'eac_ruby_utils/patches/hash/sym_keys_hash'
require 'eac_config/paths_hash'
require 'eac_ruby_utils/simple_cache'

module EacConfig
  # @deprecated Use {EacConfig::YamlFileNode} instead.
  class OldConfigs
    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
      ::EacConfig::OldConfigs::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

185 entries across 185 versions & 4 rubygems

Version Path
eac_tools-0.82.0 sub/eac_config/lib/eac_config/old_configs.rb
eac_tools-0.81.0 sub/eac_config/lib/eac_config/old_configs.rb
eac_tools-0.80.0 sub/eac_config/lib/eac_config/old_configs.rb
eac_tools-0.79.0 sub/eac_config/lib/eac_config/old_configs.rb
eac_config-0.14.1 lib/eac_config/old_configs.rb
eac_tools-0.78.0 sub/eac_config/lib/eac_config/old_configs.rb
eac_tools-0.77.1 sub/eac_config/lib/eac_config/old_configs.rb
eac_tools-0.77.0 sub/eac_config/lib/eac_config/old_configs.rb
eac_tools-0.76.1 sub/eac_config/lib/eac_config/old_configs.rb
eac_tools-0.76.0 sub/eac_config/lib/eac_config/old_configs.rb
eac_tools-0.75.2 sub/eac_config/lib/eac_config/old_configs.rb
eac_tools-0.75.1 sub/eac_config/lib/eac_config/old_configs.rb
eac_tools-0.75.0 sub/eac_config/lib/eac_config/old_configs.rb
eac_tools-0.74.1 sub/eac_config/lib/eac_config/old_configs.rb
eac_tools-0.74.0 sub/eac_config/lib/eac_config/old_configs.rb
eac_config-0.14.0 lib/eac_config/old_configs.rb
eac_tools-0.73.0 sub/eac_config/lib/eac_config/old_configs.rb
eac_config-0.13.0 lib/eac_config/old_configs.rb
eac_tools-0.72.0 sub/eac_config/lib/eac_config/old_configs.rb
eac_tools-0.70.1 sub/eac_config/lib/eac_config/old_configs.rb