Sha256: 2743a89070d206fc614a45714e9d5389da16638d2e800545457767f78b18c59e

Contents?: true

Size: 1.39 KB

Versions: 15

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module Prefab
  # Records the result of evaluating a config's criteria and forensics for reporting
  class Evaluation
    attr_reader :value

    def initialize(config:, value:, value_index:, config_row_index:, context:, resolver:)
      @config = config
      @value = value
      @value_index = value_index
      @config_row_index = config_row_index
      @context = context
      @resolver = resolver
    end

    def unwrapped_value
      deepest_value.unwrap
    end

    def reportable_value
      deepest_value.reportable_value
    end

    def report_and_return(evaluation_summary_aggregator)
      report(evaluation_summary_aggregator)

      unwrapped_value
    end

    private

    def report(evaluation_summary_aggregator)
      return if @config.config_type == :LOG_LEVEL
      evaluation_summary_aggregator&.record(
        config_key: @config.key,
        config_type: @config.config_type,
        counter: {
          config_id: @config.id,
          config_row_index: @config_row_index,
          conditional_value_index: @value_index,
          selected_value: deepest_value.reportable_wrapped_value,
          weighted_value_index: deepest_value.weighted_value_index,
          selected_index: nil # TODO
        })
    end

    def deepest_value
      @deepest_value ||= Prefab::ConfigValueUnwrapper.deepest_value(@value, @config, @context, @resolver)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
prefab-cloud-ruby-1.6.0 lib/prefab/evaluation.rb
prefab-cloud-ruby-1.5.1 lib/prefab/evaluation.rb
prefab-cloud-ruby-1.6.0.pre2 lib/prefab/evaluation.rb
prefab-cloud-ruby-1.6.0.pre1 lib/prefab/evaluation.rb
prefab-cloud-ruby-0 lib/prefab/evaluation.rb
prefab-cloud-ruby-1.5.0 lib/prefab/evaluation.rb
prefab-cloud-ruby-1.4.5 lib/prefab/evaluation.rb
prefab-cloud-ruby-1.4.4 lib/prefab/evaluation.rb
prefab-cloud-ruby-1.4.3 lib/prefab/evaluation.rb
prefab-cloud-ruby-1.4.2 lib/prefab/evaluation.rb
prefab-cloud-ruby-1.4.1 lib/prefab/evaluation.rb
prefab-cloud-ruby-1.4.0 lib/prefab/evaluation.rb
prefab-cloud-ruby-1.3.2 lib/prefab/evaluation.rb
prefab-cloud-ruby-1.3.1 lib/prefab/evaluation.rb
prefab-cloud-ruby-1.3.0 lib/prefab/evaluation.rb