Sha256: e8fb604fd7a0f6b374693d643776a7d4ebcfb6114b984af6714b47d93c6e9eec

Contents?: true

Size: 1.65 KB

Versions: 9

Compression:

Stored size: 1.65 KB

Contents

module ThreeScaleToolbox
  module Commands
    module PlansCommand
      module Import
        class ImportMetricsStep
          include Step
          ##
          # Writes Plan metrics and methods
          def call
            missing_metrics.each(&method(:create_metric))
            missing_methods.each(&method(:create_method))

            # invalidate memoized methods and metrics
            invalidate_service_methods
            invalidate_service_metrics
          end

          private

          def missing_metrics
            ThreeScaleToolbox::Helper.array_difference(resource_metrics, service_metrics) do |a, b|
              ThreeScaleToolbox::Helper.compare_hashes(a, b, ['system_name'])
            end
          end

          def missing_methods
            ThreeScaleToolbox::Helper.array_difference(resource_methods, service_methods) do |a, b|
              ThreeScaleToolbox::Helper.compare_hashes(a, b, ['system_name'])
            end
          end

          def create_metric(metric_attrs)
            metric = ThreeScaleToolbox::Entities::Metric.create(service: service,
                                                                attrs: metric_attrs)
            puts "Created metric: #{metric.attrs['system_name']}"
          end

          def create_method(method_attrs)
            method = ThreeScaleToolbox::Entities::Method.create(service: service,
                                                                parent_id: service_hits['id'],
                                                                attrs: method_attrs)
            puts "Created method: #{method.attrs['system_name']}"
          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/import/import_plan_metrics_step.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb
3scale_toolbox-0.16.0 lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb
3scale_toolbox-0.15.0 lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb