Sha256: 10cd4b4bed6510a477a9c80ff631ee89c1c91dd43f87c85d95630a00c64c446b

Contents?: true

Size: 1.63 KB

Versions: 101

Compression:

Stored size: 1.63 KB

Contents

require "securerandom"

module CC
  module Analyzer
    class EnginesRunner
      InvalidEngineName = Class.new(StandardError)
      NoEnabledEngines = Class.new(StandardError)

      def initialize(registry, formatter, source_dir, config, requested_paths = [], container_label = nil)
        @registry = registry
        @formatter = formatter
        @source_dir = source_dir
        @config = config
        @requested_paths = requested_paths
        @container_label = container_label
      end

      def run(container_listener = ContainerListener.new)
        raise NoEnabledEngines if engines.empty?

        @formatter.started

        engines.each { |engine| run_engine(engine, container_listener) }

        @formatter.finished
      ensure
        @formatter.close if @formatter.respond_to?(:close)
      end

      private

      attr_reader :requested_paths

      def build_engine(built_config)
        Engine.new(
          built_config.name,
          built_config.registry_entry,
          built_config.code_path,
          built_config.config,
          built_config.container_label,
        )
      end

      def configs
        EnginesConfigBuilder.new(
          registry: @registry,
          config: @config,
          container_label: @container_label,
          source_dir: @source_dir,
          requested_paths: requested_paths,
        ).run
      end

      def engines
        @engines ||= configs.map { |result| build_engine(result) }
      end

      def run_engine(engine, container_listener)
        @formatter.engine_running(engine) do
          engine.run(@formatter, container_listener)
        end
      end
    end
  end
end

Version data entries

101 entries across 101 versions & 1 rubygems

Version Path
codeclimate-0.14.3 lib/cc/analyzer/engines_runner.rb