Sha256: 532e98dbfdf3df3495f164cee97f19fcd764f80109a854340d750a8f859f7ce5

Contents?: true

Size: 1.09 KB

Versions: 29

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/simple_cache'
require 'yaml'
require 'eac_launcher/instances/settings'

module EacLauncher
  class Context
    class Settings
      include ::EacRubyUtils::SimpleCache

      def initialize(file)
        unless ::File.exist?(file)
          ::FileUtils.mkdir_p(::File.dirname(file))
          ::File.write(file, {}.to_yaml)
        end
        @data = YAML.load_file(file)
      end

      def instance_settings(instance)
        ::EacLauncher::Instances::Settings.new(value(['Instances', instance.name]))
      end

      private

      def excluded_projects_uncached
        enum_value(%w[Projects Exclude])
      end

      def excluded_paths_uncached
        enum_value(%w[Paths Exclude])
      end

      def enum_value(path)
        r = value(path)
        r.is_a?(Enumerable) ? r : []
      end

      def value(path)
        node_value(@data, path)
      end

      def node_value(data, path)
        return data if path.empty?
        return nil unless data.is_a?(Hash)

        node_value(data[path.first], path.drop(1))
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
avm-tools-0.63.0 lib/eac_launcher/context/settings.rb
avm-tools-0.62.4 lib/eac_launcher/context/settings.rb
avm-tools-0.62.3 lib/eac_launcher/context/settings.rb
avm-tools-0.62.2 lib/eac_launcher/context/settings.rb
avm-tools-0.62.1 lib/eac_launcher/context/settings.rb
avm-tools-0.62.0 lib/eac_launcher/context/settings.rb
avm-tools-0.61.0 lib/eac_launcher/context/settings.rb
avm-tools-0.60.0 lib/eac_launcher/context/settings.rb
avm-tools-0.59.0 lib/eac_launcher/context/settings.rb
avm-tools-0.58.1 lib/eac_launcher/context/settings.rb
avm-tools-0.58.0 lib/eac_launcher/context/settings.rb
avm-tools-0.57.0 lib/eac_launcher/context/settings.rb
avm-tools-0.56.0 lib/eac_launcher/context/settings.rb
avm-tools-0.55.0 lib/eac_launcher/context/settings.rb
avm-tools-0.54.2 lib/eac_launcher/context/settings.rb
avm-tools-0.54.1 lib/eac_launcher/context/settings.rb
avm-tools-0.54.0 lib/eac_launcher/context/settings.rb
avm-tools-0.53.0 lib/eac_launcher/context/settings.rb
avm-tools-0.52.0 lib/eac_launcher/context/settings.rb
avm-tools-0.51.0 lib/eac_launcher/context/settings.rb