Sha256: f367b3589c81a4b949a9029a1464b2e56d7ca8df7640c7d0ad54fe1bdf6fcacd

Contents?: true

Size: 1.37 KB

Versions: 56

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

require 'ruby-progressbar'
require 'avm/launcher/instances/base'

module EacLauncher
  class Context
    class InstanceDiscovery
      attr_reader :instances

      def initialize(context)
        @context = context
        @progress = ::ProgressBar.create(title: 'Instance discovery', total: 1)
        @instances = path_instances(@context.root, nil)
      ensure
        @progress&.finish
      end

      private

      def path_instances(path, parent_instance)
        update_progress_format(path)
        on_rescued_path_instances(path) do |r|
          if path.project?
            parent_instance = ::Avm::Launcher::Instances::Base.instanciate(path, parent_instance)
            r << path
          end
          children = path.children
          update_progress_count(children)
          r.concat(children.flat_map { |c| path_instances(c, parent_instance) })
        end
      end

      def on_rescued_path_instances(path)
        r = []
        begin
          yield(r) if path.included?
        rescue StandardError => e
          warn("#{path}: #{e}")
        end
        r
      end

      def update_progress_format(path)
        @progress.format = "%t (Paths: %c/%C, Current: #{path.logical}) |%B| %a"
      end

      def update_progress_count(children)
        @progress.total += children.count
        @progress.increment
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
avm-tools-0.84.0 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.83.0 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.82.1 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.82.0 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.81.0 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.80.0 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.79.0 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.78.0 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.77.0 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.76.1 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.76.0 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.75.1 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.75.0 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.74.1 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.74.0 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.73.0 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.72.0 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.71.0 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.70.2 lib/eac_launcher/context/instance_discovery.rb
avm-tools-0.70.1 lib/eac_launcher/context/instance_discovery.rb