Class: ThreeScaleToolbox::CRD::ProductParser
- Inherits:
-
Object
- Object
- ThreeScaleToolbox::CRD::ProductParser
show all
- Defined in:
- lib/3scale_toolbox/crds/product_parser.rb
Defined Under Namespace
Classes: ApplicationPlan, BackendUsage, Limit, MappingRule, Method, Metric, PolicyChainItem, PricingRule
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ProductParser.
23
24
25
26
|
# File 'lib/3scale_toolbox/crds/product_parser.rb', line 23
def initialize(cr)
@cr = cr
@deployment_parser = ProductDeploymentParser.new(cr.dig('spec', 'deployment') || {})
end
|
Instance Attribute Details
#cr ⇒ Object
Returns the value of attribute cr.
21
22
23
|
# File 'lib/3scale_toolbox/crds/product_parser.rb', line 21
def cr
@cr
end
|
#deployment_parser ⇒ Object
Returns the value of attribute deployment_parser.
21
22
23
|
# File 'lib/3scale_toolbox/crds/product_parser.rb', line 21
def deployment_parser
@deployment_parser
end
|
Instance Method Details
#application_plans ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/3scale_toolbox/crds/product_parser.rb', line 64
def application_plans
@application_plans ||= (cr.dig('spec', 'applicationPlans') || {}).map do |system_name, plan|
ApplicationPlan.new(system_name, plan['name'], plan['appsRequireApproval'],
plan['trialPeriod'], plan['setupFee'], plan['custom'], plan['state'],
plan['costMonth'], parse_limits(plan), parse_pricing_rules(plan))
end
end
|
#backend_usages ⇒ Object
72
73
74
75
76
|
# File 'lib/3scale_toolbox/crds/product_parser.rb', line 72
def backend_usages
@backend_usages ||= (cr.dig('spec', 'backendUsages') || {}).map do |backend_system_name, usage|
BackendUsage.new(backend_system_name, usage['path'])
end
end
|
#description ⇒ Object
36
37
38
|
# File 'lib/3scale_toolbox/crds/product_parser.rb', line 36
def description
cr.dig('spec', 'description')
end
|
#mapping_rules ⇒ Object
52
53
54
55
56
57
|
# File 'lib/3scale_toolbox/crds/product_parser.rb', line 52
def mapping_rules
@mapping_rules ||= (cr.dig('spec', 'mappingRules') || []).map do |mapping_rule|
MappingRule.new(mapping_rule['metricMethodRef'], mapping_rule['httpMethod'],
mapping_rule['pattern'], mapping_rule['increment'], mapping_rule['last'])
end
end
|
#methods ⇒ Object
46
47
48
49
50
|
# File 'lib/3scale_toolbox/crds/product_parser.rb', line 46
def methods
@methods ||= (cr.dig('spec', 'methods') || {}).map do |system_name, method|
Method.new(system_name, method['friendlyName'], method['description'])
end
end
|
#metrics ⇒ Object
40
41
42
43
44
|
# File 'lib/3scale_toolbox/crds/product_parser.rb', line 40
def metrics
@metrics ||= (cr.dig('spec', 'metrics') || {}).map do |system_name, metric|
Metric.new(system_name, metric['friendlyName'], metric['description'], metric['unit'])
end
end
|
#metrics_index ⇒ Object
Metrics and methods index by system_name
60
61
62
|
# File 'lib/3scale_toolbox/crds/product_parser.rb', line 60
def metrics_index
@metrics_index ||= (methods + metrics).each_with_object({}) { |metric, h| h[metric.system_name] = metric }
end
|
#name ⇒ Object
32
33
34
|
# File 'lib/3scale_toolbox/crds/product_parser.rb', line 32
def name
cr.dig('spec', 'name')
end
|
#policy_chain ⇒ Object
91
92
93
94
95
|
# File 'lib/3scale_toolbox/crds/product_parser.rb', line 91
def policy_chain
@policy_chain ||= (cr.dig('spec', 'policies') || []).map do |item|
PolicyChainItem.new(item['name'], item['version'], item['configuration'], item['enabled'])
end
end
|
#system_name ⇒ Object
28
29
30
|
# File 'lib/3scale_toolbox/crds/product_parser.rb', line 28
def system_name
cr.dig('spec', 'systemName')
end
|