Sha256: 272e84f0b5b2b58e2b31c9c5c25bab7267ce2b92c1d79281871b5a0104ffdf2e

Contents?: true

Size: 1.49 KB

Versions: 5

Compression:

Stored size: 1.49 KB

Contents

module EacLauncher
  class Context
    include ::Eac::SimpleCache

    class << self
      def current
        default
      end

      def default
        @default ||= Context.new(
          ENV['EAC_LAUNCHER_PROJECTS_ROOT'] || '.',
          ENV['EAC_LAUNCHER_SETTINGS_FILE'] ||
            ::File.join(ENV['HOME'], '.config', 'eac_launcher', 'settings.yml')
        )
      end
    end

    attr_reader :root, :settings
    attr_accessor :publish_options

    def initialize(projects_root, settings_file)
      @root = ::EacLauncher::Instances::Base.new(projects_root, nil)
      @settings = ::EacLauncher::Context::Settings.new(settings_file)
      @publish_options = { new: false, confirm: false, stereotype: nil }
    end

    def cache_root
      File.join(ENV['HOME'], '.cache', 'cli-utils', 'dev')
    end

    private

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

    def instances_uncached
      instance_instances(root)
    end

    def instance_instances(i)
      r = []
      r << i if include_instance?(i)
      r += i.children.flat_map { |c| instance_instances(c) }
      r
    end

    def include_project?(p)
      !@settings.excluded_projects.include?(p.name)
    end

    def include_instance?(i)
      i.project? && !@settings.excluded_projects.include?(i.project_name)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
eac_launcher-0.1.3 lib/eac_launcher/context.rb
eac_launcher-0.1.4 lib/eac_launcher/context.rb
eac_launcher-0.1.2 lib/eac_launcher/context.rb
eac_launcher-0.1.1 lib/eac_launcher/context.rb
eac_launcher-0.1.0 lib/eac_launcher/context.rb