Sha256: f4bfbba9649c716677e8136217f08634c47e8a2d58ee2c9258ac69cbd7033a45

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

module ThreeScaleToolbox
  module Commands
    module PlansCommand
      module Import
        class ImportBackendMetricsStep
          include Step
          ##
          # Writes Plan metrics and methods
          def call
            resource_backend_metrics.each(&method(:create_metric))
            resource_backend_methods.each(&method(:create_method))
          end

          private

          def create_metric(metric_attrs)
            backend = find_backend(metric_attrs.fetch('backend_system_name'))

            unless backend.metrics.any? { |m| m.system_name == metric_attrs.fetch('system_name') }
              Entities::BackendMetric.create(backend: backend, attrs: metric_attrs)
              puts "Created backend metric: #{metric_attrs.fetch('system_name')}; backend: #{backend.system_name}"
            end
          end

          def create_method(method_attrs)
            backend = find_backend(method_attrs.fetch('backend_system_name'))

            unless backend.methods.any? { |m| m.system_name == method_attrs.fetch('system_name') }
              Entities::BackendMethod.create(backend: backend, attrs: method_attrs)
              puts "Created backend method: #{method_attrs.fetch('system_name')}; backend: #{backend.system_name}"
            end
          end
        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/commands/plans_command/import/import_backend_metrics_step.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/commands/plans_command/import/import_backend_metrics_step.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/commands/plans_command/import/import_backend_metrics_step.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/commands/plans_command/import/import_backend_metrics_step.rb