Module: ThreeScaleToolbox::Commands::PlansCommand::Import::Step

Included in:
CreateOrUpdateAppPlanStep, ImportMetricLimitsStep, ImportMetricsStep, ImportPlanFeaturesStep, ImportPricingRulesStep
Defined in:
lib/3scale_toolbox/commands/plans_command/import/step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 6

def context
  @context
end

Instance Method Details

#artifacts_resourceObject

deserialized artifacts content



77
78
79
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 77

def artifacts_resource
  context[:artifacts_resource]
end

#fileObject



16
17
18
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 16

def file
  context[:file]
end

#find_feature_by_system_name(system_name) ⇒ Object



81
82
83
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 81

def find_feature_by_system_name(system_name)
  service_features.find { |feature| feature['system_name'] == system_name }
end

#find_metric_by_system_name(system_name) ⇒ Object



85
86
87
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 85

def find_metric_by_system_name(system_name)
  service_metrics_and_methods.find { |metric| metric.system_name == system_name }
end

#initialize(context) ⇒ Object



8
9
10
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 8

def initialize(context)
  @context = context
end

#planObject



38
39
40
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 38

def plan
  context[:plan] ||= find_plan
end

#plan_system_nameObject

can be id or system_name



30
31
32
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 30

def plan_system_name
  context[:plan_system_name] || artifacts_resource.dig('plan', 'system_name')
end

#resource_featuresObject



64
65
66
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 64

def resource_features
  artifacts_resource['plan_features'] || []
end

#resource_limitsObject



56
57
58
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 56

def resource_limits
  artifacts_resource['limits'] || []
end

#resource_methodsObject



52
53
54
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 52

def resource_methods
  artifacts_resource['methods'] || []
end

#resource_metricsObject



48
49
50
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 48

def resource_metrics
  artifacts_resource['metrics'] || []
end

#resource_planObject



42
43
44
45
46
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 42

def resource_plan
  artifacts_resource.fetch('plan') do
    raise ThreeScaleToolbox::Error, 'Invalid content. Plan not found'
  end
end

#resource_pricing_rulesObject



60
61
62
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 60

def resource_pricing_rules
  artifacts_resource['pricingrules'] || []
end

#resultObject



34
35
36
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 34

def result
  context[:result] ||= {}
end

#serviceObject



12
13
14
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 12

def service
  context[:service] ||= find_service
end

#service_featuresObject



72
73
74
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 72

def service_features
  context[:service_features] ||= service.features
end

#service_metrics_and_methodsObject



68
69
70
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 68

def service_metrics_and_methods
  service.metrics + service.methods
end

#service_system_nameObject

can be id or system_name



25
26
27
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 25

def service_system_name
  context[:service_system_name]
end

#threescale_clientObject



20
21
22
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 20

def threescale_client
  context[:threescale_client]
end