Sha256: c7d3561b4581404f5f1ef89f083ac081334b9913bd73f5411c2e3c7bb90712b6

Contents?: true

Size: 1.53 KB

Versions: 9

Compression:

Stored size: 1.53 KB

Contents

module ThreeScaleToolbox
  module Commands
    module PlansCommand
      module Export
        class ReadPlanMethods
          include Step
          ##
          # Compute unique list of methods from limits and pricingrules
          def call
            methods = [
              limit_methods,
              pricingrule_methods
            ]
            result[:plan_methods] = methods.each_with_object({}) { |elem, acc| acc.merge!(elem) }
          end

          private

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

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

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

          def filtered_pricing_rule_methods
            result[:pricingrules].select { |limit| limit.dig('metric', 'type') == 'method' }
          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_methods_step.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb
3scale_toolbox-0.16.0 lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb
3scale_toolbox-0.15.0 lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb