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



97
98
99
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 97

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



101
102
103
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 101

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



105
106
107
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 105

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

#invalidate_service_methodsObject



88
89
90
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 88

def invalidate_service_methods
  context[:service_methods] = nil
end

#invalidate_service_metricsObject



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

def invalidate_service_metrics
  context[:service_metrics] = nil
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



92
93
94
# File 'lib/3scale_toolbox/commands/plans_command/import/step.rb', line 92

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

#service_hitsObject



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

def service_hits
  context[:service_hits] ||= service.hits
end

#service_methodsObject



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

def service_methods
  context[:service_methods] ||= service.methods(service_hits['id'])
end

#service_metricsObject



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

def service_metrics
  context[:service_metrics] ||= service.metrics
end

#service_metrics_and_methodsObject



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

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