class ThreeScaleToolbox::CRD::ProductParser
Constants
- ApplicationPlan
- BackendUsage
- Limit
- MappingRule
- Method
- Metric
- PolicyChainItem
- PricingRule
Attributes
cr[R]
deployment_parser[R]
Public Class Methods
new(cr)
click to toggle source
# File lib/3scale_toolbox/crds/product_parser.rb, line 23 def initialize(cr) @cr = cr @deployment_parser = ProductDeploymentParser.new(cr.dig('spec', 'deployment') || {}) end
Public Instance Methods
application_plans()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/3scale_toolbox/crds/product_parser.rb, line 36 def description cr.dig('spec', 'description') end
mapping_rules()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
Metrics and methods index by system_name
# 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()
click to toggle source
# File lib/3scale_toolbox/crds/product_parser.rb, line 32 def name cr.dig('spec', 'name') end
policy_chain()
click to toggle source
# 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()
click to toggle source
# File lib/3scale_toolbox/crds/product_parser.rb, line 28 def system_name cr.dig('spec', 'systemName') end
Private Instance Methods
parse_limits(plan)
click to toggle source
# File lib/3scale_toolbox/crds/product_parser.rb, line 99 def parse_limits(plan) plan.fetch('limits', []).map do |limit| Limit.new(limit['period'], limit['value'], limit.dig('metricMethodRef', 'systemName'), limit.dig('metricMethodRef', 'backend')) end end
parse_pricing_rules(plan)
click to toggle source
# File lib/3scale_toolbox/crds/product_parser.rb, line 106 def parse_pricing_rules(plan) plan.fetch('pricingRules', []).map do |pr| PricingRule.new(pr['from'], pr['to'], pr['pricePerUnit'], pr.dig('metricMethodRef', 'systemName'), pr.dig('metricMethodRef', 'backend')) end end