Sha256: b5074f083fe473a7720b3bf9bc757f7e0fc654a21f52c21dc89913ce60aefcbc

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

module ThreeScaleToolbox
  module Commands
    module PlansCommand
      module Export
        class ReadPlanMetrics
          include Step
          ##
          # Compute unique list of metrics limits and pricingrules
          def call
            all_metrics = [
              limit_metrics,
              pricingrule_metrics
            ]
            result[:plan_metrics] = all_metrics.each_with_object({}) { |elem, acc| acc.merge!(elem) }
          end

          private

          def limit_metrics
            # multiple limits can reference the same metric
            filtered_limit_metrics.each_with_object({}) do |elem, acc|
              # find_metric should not return nil.
              # It is assumed that metric_id refers to existing element from previous steps
              acc[elem['metric_id']] = find_metric(elem['metric_id']).attrs
            end
          end

          def filtered_limit_metrics
            result[:limits].select { |limit| limit.dig('metric', 'type') == 'metric' }
          end

          def pricingrule_metrics
            filtered_pricing_rule_metrics.each_with_object({}) do |elem, acc|
              # find_metric should not return nil.
              # It is assumed that metric_id refers to existing element from previous steps
              acc[elem['metric_id']] = find_metric(elem['metric_id']).attrs
            end
          end

          def filtered_pricing_rule_metrics
            result[:pricingrules].select { |limit| limit.dig('metric', 'type') == 'metric' }
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
3scale_toolbox-0.19.2 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb