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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#context ⇒ Object (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_resource ⇒ Object

deserialized artifacts content



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

def artifacts_resource
  context[:artifacts_resource]
end

#file ⇒ Object



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



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

def find_feature_by_system_name(system_name)
  service_features.find { |feature| feature['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

#plan ⇒ Object



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

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

#plan_system_name ⇒ Object

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_backend_methods ⇒ Object



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

def resource_backend_methods
  resource_methods.select{ |mth| mth.has_key? 'backend_system_name' }
end

#resource_backend_metrics ⇒ Object



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

def resource_backend_metrics
  resource_metrics.select{ |m| m.has_key? 'backend_system_name' }
end

#resource_features ⇒ Object



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

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

#resource_limits ⇒ Object



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

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

#resource_methods ⇒ Object



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

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

#resource_metrics ⇒ Object



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

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

#resource_plan ⇒ Object



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_rules ⇒ Object



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

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

#resource_product_methods ⇒ Object



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

def resource_product_methods
  resource_methods.reject{ |mth| mth.has_key? 'backend_system_name' }
end

#resource_product_metrics ⇒ Object



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

def resource_product_metrics
  resource_metrics.reject{ |m| m.has_key? 'backend_system_name' }
end

#result ⇒ Object



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

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

#service ⇒ Object



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

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

#service_features ⇒ Object



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

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

#service_system_name ⇒ Object

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_client ⇒ Object



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

def threescale_client
  context[:threescale_client]
end