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.4.29 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.28 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.27 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.26 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.25 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.24 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.23 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.22 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.21 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.20 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.19 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.18 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.17 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.16 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.15 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.14 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.13 lib/inferno/utils/preset_processor.rb
inferno_core-0.4.12 lib/inferno/utils/preset_processor.rb