Sha256: b1625d2420280366995bc389a0778b041011f4a102f1390cd23712d2ff7967d0

Contents?: true

Size: 1.57 KB

Versions: 38

Compression:

Stored size: 1.57 KB

Contents

module Inferno
  module Utils
    # This class determines which values to use in a preset based on the suite
    # options chosen in a session.
    # @api private
    class PresetProcessor
      attr_accessor :preset, :session, :suite, :suite_inputs, :suite_options

      def initialize(preset, session)
        self.preset = preset
        self.session = session
        self.suite = session.test_suite
        self.suite_inputs = suite.available_inputs.transform_values(&:to_hash)
        self.suite_options = session.suite_options
      end

      # Returns the list of inputs which need to be persisted, with options
      # applied.
      def processed_inputs
        preset.inputs
          .map { |input| input_for_options(input) }
          .compact
      end

      private

      def input_for_options(input)
        if suite_inputs[input[:name].to_sym].nil?
          Inferno::Application['logger'].warn("Unknown input #{input[:name]} in preset #{preset.id}")
          return
        end

        {
          name: input[:name],
          value: value(input),
          type: suite_inputs[input[:name].to_sym][:type]
        }
      end

      def value(input)
        value_for_option(input).presence || input[:value]
      end

      def value_for_option(input)
        input[:value_for_options]&.find do |option_value|
          option_value[:options].all? do |option|
            suite_options.any? do |suite_option|
              suite_option.id.to_s == option[:name] && suite_option.value == option[:value]
            end
          end
        end&.dig(:value)
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
inferno_core-0.6.1 lib/inferno/utils/preset_processor.rb
inferno_core-0.6.0 lib/inferno/utils/preset_processor.rb
inferno_core-0.5.4 lib/inferno/utils/preset_processor.rb
inferno_core-0.5.3 lib/inferno/utils/preset_processor.rb
inferno_core-0.5.2 lib/inferno/utils/preset_processor.rb
inferno_core-0.5.1 lib/inferno/utils/preset_processor.rb
inferno_core-0.5.0 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.44 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.43 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.42 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.41 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.40 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.39 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.38 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.35 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.34 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.33 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.32 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.31 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.30 lib/inferno/utils/preset_processor.rb