Sha256: 8dcef76a455c78855cde07e37c7ac41ec0b45d0a82e8467a4dd30d61e2db23cf

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

module EacLauncher
  class Context
    include ::Eac::SimpleCache
    include ::EacRubyUtils::Console::Speaker

    DEFAULT_PROJECTS_ROOT = '.'.freeze
    DEFAULT_SETTINGS_FILE = ::File.join(ENV['HOME'], '.config', 'eac_launcher', 'settings.yml')
    DEFAULT_CACHE_ROOT = ::File.join(ENV['HOME'], '.cache', 'eac_launcher')

    class << self
      attr_writer :current

      def current
        @current ||= default
      end

      def default
        @default ||= Context.new
      end
    end

    attr_reader :root, :settings, :cache_root
    attr_accessor :publish_options, :recache

    def initialize(options = {})
      @options = options.with_indifferent_access
      @root = ::EacLauncher::Paths::Logical.new(self, nil, build_option(:projects_root), '/')
      @settings = ::EacLauncher::Context::Settings.new(build_option(:settings_file))
      @cache_root = build_option(:cache_root)
      @publish_options = { new: false, confirm: false, stereotype: nil }
      @instance_manager = ::EacLauncher::Context::InstanceManager.new(self)
      @recache = false
    end

    def instance(name)
      instances.find { |i| i.name == name }
    end

    def instances
      @instance_manager.instances
    end

    private

    def build_option(key)
      @options[key] || env_option(key) || default_option(key)
    end

    def env_option(key)
      ENV["EAC_LAUNCHER_#{key}".underscore.upcase]
    end

    def default_option(key)
      self.class.const_get("DEFAULT_#{key}".underscore.upcase)
    end

    def projects_uncached
      r = {}
      instances.each do |i|
        r[i.project_name] ||= []
        r[i.project_name] << i
      end
      r.map { |name, instances| ::EacLauncher::Project.new(name, instances) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eac_launcher-0.4.0 lib/eac_launcher/context.rb