Sha256: a94bfabe899d30b8955bb1b12049f7ca00ae12ede797a895668daa6cd29e8d27

Contents?: true

Size: 1.44 KB

Versions: 4

Compression:

Stored size: 1.44 KB

Contents

module ThreeScaleToolbox
  module CRD
    module PricingRuleSerializer
      def to_cr
        {
          'from' => min,
          'to' => max,
          'pricePerUnit' => cost_per_unit,
          'metricMethodRef' => metric_system_name,
        }
      end

      def metric_system_name
        # Find in service methods
        # Find in service metrics
        # Find in backend methods
        # Find in backend metrics
        if (method = plan.service.methods.find { |m| m.id == metric_id })
          { 'systemName' => method.system_name }
        elsif (metric = plan.service.metrics.find { |m| m.id == metric_id })
          { 'systemName' => metric.system_name }
        elsif (backend = backend_from_metric_link)
          if (backend_metric = backend.metrics.find { |m| m.id == metric_id })
            { 'systemName' => backend_metric.system_name, 'backend' => backend.system_name }
          elsif (backend_method = backend.methods.find { |m| m.id == metric_id })
            { 'systemName' => backend_method.system_name, 'backend' => backend.system_name }
          else
            raise ThreeScaleToolbox::Error, "Unexpected error. PricingRule #{id} " \
              "referencing to metric id #{metric_id} which has not been found"
          end
        else
          raise ThreeScaleToolbox::Error, "Unexpected error. PricingRule #{id} " \
            "referencing to metric id #{metric_id} which has not been found"
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.1 lib/3scale_toolbox/crds/pricing_rule_dump.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/crds/pricing_rule_dump.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/crds/pricing_rule_dump.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/crds/pricing_rule_dump.rb