Sha256: 326f07a402baa791b2728a92de073a01118e878d2c6e6a742ba10631f87f395e

Contents?: true

Size: 1.46 KB

Versions: 254

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

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

module Avm
  module Launcher
    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
end

Version data entries

254 entries across 254 versions & 3 rubygems

Version Path
avm-0.90.1 lib/avm/launcher/context/instance_discovery.rb
eac_tools-0.87.1 sub/avm/lib/avm/launcher/context/instance_discovery.rb
avm-0.90.0 lib/avm/launcher/context/instance_discovery.rb
eac_tools-0.87.0 sub/avm/lib/avm/launcher/context/instance_discovery.rb
avm-0.89.0 lib/avm/launcher/context/instance_discovery.rb
eac_tools-0.86.12 sub/avm/lib/avm/launcher/context/instance_discovery.rb
avm-0.88.0 lib/avm/launcher/context/instance_discovery.rb
eac_tools-0.86.11 sub/avm/lib/avm/launcher/context/instance_discovery.rb
avm-0.87.0 lib/avm/launcher/context/instance_discovery.rb
eac_tools-0.86.8 sub/avm/lib/avm/launcher/context/instance_discovery.rb
avm-0.86.2 lib/avm/launcher/context/instance_discovery.rb
eac_tools-0.86.7 sub/avm/lib/avm/launcher/context/instance_discovery.rb
avm-0.86.1 lib/avm/launcher/context/instance_discovery.rb
eac_tools-0.86.5 sub/avm/lib/avm/launcher/context/instance_discovery.rb
avm-0.86.0 lib/avm/launcher/context/instance_discovery.rb
eac_tools-0.86.4 sub/avm/lib/avm/launcher/context/instance_discovery.rb
eac_tools-0.86.3 sub/avm/lib/avm/launcher/context/instance_discovery.rb
avm-0.85.0 lib/avm/launcher/context/instance_discovery.rb
eac_tools-0.86.2 sub/avm/lib/avm/launcher/context/instance_discovery.rb
avm-0.84.3 lib/avm/launcher/context/instance_discovery.rb