Sha256: 5ae9c5acdcf770293f24daa2c3319ca6f180d9ff8791058c17ac01d25216f09d

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

module ThreeScaleToolbox
  module CRD
    module Limit
      def to_cr
        {
          'period' => period,
          'value' => value,
          '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)
          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. Limit #{id} " \
              "referencing to metric id #{metric_id} which has not been found"
          end
        else
          raise ThreeScaleToolbox::Error, "Unexpected error. Limit #{id} " \
            "referencing to metric id #{metric_id} which has not been found"
        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/crds/limit_dump.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/crds/limit_dump.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/crds/limit_dump.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/crds/limit_dump.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/crds/limit_dump.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/crds/limit_dump.rb