Sha256: a6e9e03294eddf0329afdf32a3cc45a2ce0068991b67271b00dfd6f5398fad8d

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

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

          def call
            source_plans = source.plans
            target_plans = target.plans
            missing_plans = missing_app_plans(source_plans, target_plans)
            missing_plans.each do |plan|
              plan.delete('links')
              plan.delete('default') # TODO: handle default plan
              if plan.delete('custom') # TODO: what to do with custom plans?
                puts "skipping custom plan #{plan}"
              else
                ThreeScaleToolbox::Entities::ApplicationPlan.create(service: target, plan_attrs: plan)
              end
            end
            puts "target service missing #{missing_plans.size} application plans"
          end

          private

          def missing_app_plans(source_plans, target_plans)
            ThreeScaleToolbox::Helper.array_difference(source_plans, target_plans) do |src, target|
              ThreeScaleToolbox::Helper.compare_hashes(src, target, ['system_name'])
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
3scale_toolbox-0.17.1 lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb
3scale_toolbox-0.16.0 lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb