Sha256: 995b71a4b7aaaa0459e11cad2096cac9c11048f1cb5efff89accfae5565ae930

Contents?: true

Size: 1.53 KB

Versions: 9

Compression:

Stored size: 1.53 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'])
            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'])
            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

9 entries across 9 versions & 1 rubygems

Version Path
3scale_toolbox-0.17.1 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
3scale_toolbox-0.16.0 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
3scale_toolbox-0.15.0 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb