Module: Gapic::GrpcServiceConfig::Parser
- Defined in:
- lib/gapic/grpc_service_config/parser.rb
Overview
Takes a json of a GRPC service Config and parses it into the form usable by the microgenerator templates
Constant Summary collapse
- METHOD_CONFIG_JSON_KEY =
"methodConfig"- RETRY_POLICY_JSON_KEY =
"retryPolicy"- NAMES_JSON_KEY =
"name"- SERVICE_NAME_JSON_KEY =
"service"- METHOD_NAME_JSON_KEY =
"method"- TIMEOUT_JSON_KEY =
"timeout"- INITIAL_DELAY_JSON_KEY =
"initialBackoff"- MAX_DELAY_JSON_KEY =
"maxBackoff"- MULTIPLIER_JSON_KEY =
"backoffMultiplier"- STATUS_CODES_JSON_KEY =
"retryableStatusCodes"
Class Method Summary collapse
-
.get(hash, key) ⇒ Object
Look up a key including checking its underscore form.
-
.key?(hash, key) ⇒ Boolean
Determines if the key or its underscore form exists.
-
.parse(service_config_json) ⇒ Gapic::GrpcServiceConfig::ServiceConfig
Parses ServiceConfig from a json of a GRPC service config.
Class Method Details
.get(hash, key) ⇒ Object
Look up a key including checking its underscore form
196 197 198 |
# File 'lib/gapic/grpc_service_config/parser.rb', line 196 def self.get hash, key hash[key] || hash[ActiveSupport::Inflector.underscore(key)] end |
.key?(hash, key) ⇒ Boolean
Determines if the key or its underscore form exists
185 186 187 |
# File 'lib/gapic/grpc_service_config/parser.rb', line 185 def self.key? hash, key hash.key?(key) || hash.key?(ActiveSupport::Inflector.underscore(key)) end |
.parse(service_config_json) ⇒ Gapic::GrpcServiceConfig::ServiceConfig
Parses ServiceConfig from a json of a GRPC service config
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/gapic/grpc_service_config/parser.rb', line 51 def self.parse service_config_json service_level_result = {} service_method_level_result = {} if !service_config_json.nil? && key?(service_config_json, METHOD_CONFIG_JSON_KEY) method_configs_json = get service_config_json, METHOD_CONFIG_JSON_KEY method_configs_json.each do |method_config_json| method_config = parse_config method_config_json service_names = parse_service_names get(method_config_json, NAMES_JSON_KEY) service_method_names = filter_service_method_names get(method_config_json, NAMES_JSON_KEY) service_names.each do |service_name| service_level_result[service_name] = method_config end service_method_names.each do |service_method_name| service_name = get service_method_name, SERVICE_NAME_JSON_KEY method_name = get service_method_name, METHOD_NAME_JSON_KEY service_method_level_result[service_name] ||= {} service_method_level_result[service_name][method_name] = method_config end end end ServiceConfig.new service_level_result, service_method_level_result end |