class ThreeScaleToolbox::Commands::PlansCommand::Import::ImportMetricLimitsStep

Public Instance Methods

call() click to toggle source

Writes Plan limits

# File lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb, line 9
def call
  # SET semantics
  # First, delete existing limits
  # Second, add new limits
  plan.limits.each do |limit|
    limit.delete()
    puts "Deleted existing plan limit: [metric: #{limit.metric_id}, #{limit.attrs}]"
  end

  resource_limits_processed.each do |limit_attrs|
    metric_id = limit_attrs.delete('metric_id')
    plan.create_limit(metric_id, limit_attrs)
    puts "Created plan limit: [metric: #{metric_id}, #{limit_attrs}]"
  end
end

Private Instance Methods

resource_limits_processed() click to toggle source
# File lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb, line 27
def resource_limits_processed
  resource_limits.map do |limit|
    metric = find_metric_by_system_name(limit.delete('metric_system_name'))
    # this ImportMetricLimitsStep step is assuming all metrics/methods have been created
    # in previous step, so finding metric should always succeed.
    limit.merge('metric_id' => metric.id)
  end
end