class ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyLimitsTask

Public Instance Methods

call() click to toggle source
# File lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb, line 8
def call
  plan_mapping = Helper.application_plan_mapping(source.plans, target.plans)
  plan_mapping.each do |source_plan, target_plan|
    missing_limits = compute_missing_limits(source_plan.limits, target_plan.limits)
    missing_limits.each do |limit|
      target_plan.create_limit(metrics_map.fetch(limit.metric_id), limit.attrs)
    end
    logger.info "Missing #{missing_limits.size} plan limits from target application plan " \
      "#{target_plan.id}. Source plan #{source_plan.id}"

    plans_report[target_plan.system_name] = {'application_plan_id' => target_plan.id} unless plans_report.has_key? target_plan.system_name
    plans_report[target_plan.system_name].merge!({'missing_limits_created' => missing_limits.size})
  end
end

Private Instance Methods

compute_missing_limits(source_limits, target_limits) click to toggle source
# File lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb, line 29
def compute_missing_limits(source_limits, target_limits)
  ThreeScaleToolbox::Helper.array_difference(source_limits, target_limits) do |limit, target_limit|
    limit.period == target_limit.period && metrics_map.fetch(limit.metric_id) == target_limit.metric_id
  end
end
metrics_map() click to toggle source
# File lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb, line 25
def metrics_map
  @metrics_map ||= source.metrics_mapping(target)
end