Sha256: 3c1d371fd8ad5a8a1dfad9f962bed5793afe3e7e554a3b07877522886c77cdbe

Contents?: true

Size: 1023 Bytes

Versions: 9

Compression:

Stored size: 1023 Bytes

Contents

module ThreeScaleToolbox
  module Tasks
    class CopyApplicationPlansTask
      include CopyTask

      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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
3scale_toolbox-0.15.0 lib/3scale_toolbox/tasks/copy_app_plans_task.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/tasks/copy_app_plans_task.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/tasks/copy_app_plans_task.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/tasks/copy_app_plans_task.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/tasks/copy_app_plans_task.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/tasks/copy_app_plans_task.rb
3scale_toolbox-0.11.0 lib/3scale_toolbox/tasks/copy_app_plans_task.rb
3scale_toolbox-0.10.0 lib/3scale_toolbox/tasks/copy_app_plans_task.rb
3scale_toolbox-0.9.0 lib/3scale_toolbox/tasks/copy_app_plans_task.rb