Sha256: daeb183a3dd417d80f3d7ca518ab1267c3bdc56a301d6a042c4e28e49e870b40

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

module ThreeScaleToolbox
  module Commands
    module ServiceCommand
      module CopyCommand
        class CopyApplicationPlansTask
          include Task

          def call
            missing_regular_plans.each do |plan|
              plan_attrs = plan.attrs.clone
              plan_attrs.delete('links')
              plan_attrs.delete('default') # TODO: handle default plan
              ThreeScaleToolbox::Entities::ApplicationPlan.create(service: target, plan_attrs: plan_attrs)
            end

            logger.info "target service missing #{missing_regular_plans.size} application plans"
            report['missing_application_plans_created'] = missing_regular_plans.size
          end

          private

          def missing_regular_plans
            missing_plans.reject(&:custom)
          end

          def missing_plans
            @missing_plans ||= ThreeScaleToolbox::Helper.array_difference(source.plans, target.plans) do |src, target|
              src.system_name == target.system_name
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.1 lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb