module ThreeScaleToolbox::Commands::PlansCommand::Export::Step

Attributes

context[R]

Public Class Methods

new(context) click to toggle source
# File lib/3scale_toolbox/commands/plans_command/export/step.rb, line 14
def initialize(context)
  @context = context
end

Public Instance Methods

file() click to toggle source
# File lib/3scale_toolbox/commands/plans_command/export/step.rb, line 22
def file
  context[:file]
end
metric_info(elem, elem_name) click to toggle source
# File lib/3scale_toolbox/commands/plans_command/export/step.rb, line 48
def metric_info(elem, elem_name)
  if (method = find_method(elem.metric_id))
    { 'type' => 'method', 'system_name' => method.system_name }
  elsif (metric = find_metric(elem.metric_id))
    { 'type' => 'metric', 'system_name' => metric.system_name }
  else
    raise ThreeScaleToolbox::Error, "Unexpected error. #{elem_name} #{elem.id} " \
      "referencing to metric id #{elem.metric_id} which has not been found"
  end
end
plan() click to toggle source
# File lib/3scale_toolbox/commands/plans_command/export/step.rb, line 44
def plan
  context[:plan] ||= find_plan
end
plan_system_name() click to toggle source

can be id or system_name

# File lib/3scale_toolbox/commands/plans_command/export/step.rb, line 36
def plan_system_name
  context[:plan_system_name]
end
result() click to toggle source
# File lib/3scale_toolbox/commands/plans_command/export/step.rb, line 40
def result
  context[:result] ||= {}
end
service() click to toggle source
# File lib/3scale_toolbox/commands/plans_command/export/step.rb, line 18
def service
  context[:service] ||= find_service
end
service_system_name() click to toggle source

can be id or system_name

# File lib/3scale_toolbox/commands/plans_command/export/step.rb, line 31
def service_system_name
  context[:service_system_name]
end
threescale_client() click to toggle source
# File lib/3scale_toolbox/commands/plans_command/export/step.rb, line 26
def threescale_client
  context[:threescale_client]
end

Private Instance Methods

find_method(id) click to toggle source
# File lib/3scale_toolbox/commands/plans_command/export/step.rb, line 78
def find_method(id)
  service.methods.find { |method| method.id == id }
end
find_metric(id) click to toggle source
# File lib/3scale_toolbox/commands/plans_command/export/step.rb, line 74
def find_metric(id)
  service.metrics.find { |metric| metric.id == id }
end
find_plan() click to toggle source
# File lib/3scale_toolbox/commands/plans_command/export/step.rb, line 68
def find_plan
  Entities::ApplicationPlan.find(service: service, ref: plan_system_name).tap do |p|
    raise ThreeScaleToolbox::Error, "Application plan #{plan_system_name} does not exist" if p.nil?
  end
end
find_service() click to toggle source
# File lib/3scale_toolbox/commands/plans_command/export/step.rb, line 61
def find_service
  Entities::Service.find(remote: threescale_client,
                         ref: service_system_name).tap do |svc|
    raise ThreeScaleToolbox::Error, "Service #{service_system_name} does not exist" if svc.nil?
  end
end