class Gapic::Runner
TODO: Enter docs Dooooooooocs!!!
Attributes
request[R]
Public Class Methods
new(request)
click to toggle source
Initializes the runner. @param [Google::Protobuf::Compiler::CodeGeneratorRequest] request
# File lib/gapic/runner.rb, line 30 def initialize request # parse the parameters that apply to runner and not to the api and exclude them from the request runner_param_names = ["binary_output", "generator"] runner_schema = Gapic::Schema::ParameterSchema.create( string_params_list: runner_param_names ) params = Gapic::Schema::RequestParamParser.parse_parameters_string request.parameter, param_schema: runner_schema @binary_output_path = params.filter { |p| p.config_name == "binary_output" }.first&.config_value @generator_type = params.filter { |p| p.config_name == "generator" }.first&.config_value gapic_params = params.filter { |p| !runner_param_names.include? p.config_name } # reconstruct the request parameter string without the runner parameters request.parameter = Gapic::Schema::RequestParamParser.reconstruct_parameters_string gapic_params @request = request end
run(request, generator: nil)
click to toggle source
Run protoc generation. @param [Google::Protobuf::Compiler::CodeGeneratorRequest] request @param [String] generator @return [Google::Protobuf::Compiler::CodeGeneratorResponse]
# File lib/gapic/runner.rb, line 77 def self.run request, generator: nil new(request).run generator_type: generator end
Public Instance Methods
run(generator_type: nil)
click to toggle source
Run protoc generation. @param [String] generator_type @return [Google::Protobuf::Compiler::CodeGeneratorResponse]
# File lib/gapic/runner.rb, line 51 def run generator_type: nil # save the binary file if needed write_binary_file # Retrieve generator type from protoc_options if not already provided. generator_type ||= @generator_type # Find the generator for the generator type. generator = Gapic::Generator.find generator_type # Create an API Schema from the FileDescriptorProtos api = Gapic::Schema::Api.new request, parameter_schema: generator.parameter_schema # Create and run the generator from the API. output_files = generator.new(api).generate # Create and write the response response = Google::Protobuf::Compiler::CodeGeneratorResponse.new file: output_files feature_set = Google::Protobuf::Compiler::CodeGeneratorResponse::Feature::FEATURE_PROTO3_OPTIONAL.to_i response.supported_features = feature_set response end
Private Instance Methods
write_binary_file()
click to toggle source
Save binary file with the request if the binary_output_path parameter is set
# File lib/gapic/runner.rb, line 85 def write_binary_file return unless @binary_output_path # Write binary file if the binary_output option is set File.binwrite @binary_output_path, request.to_proto end