Sha256: 7bf27da20a5125398539ff49907429cf0076a6a918cdc4783eeb1c2465d6d818

Contents?: true

Size: 1.38 KB

Versions: 4

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_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. 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

4 entries across 4 versions & 1 rubygems

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