Class: Gapic::Runner
- Inherits:
-
Object
- Object
- Gapic::Runner
- Defined in:
- lib/gapic/runner.rb
Overview
TODO: Enter docs Dooooooooocs!!!
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Class Method Summary collapse
-
.run(request, generator: nil) ⇒ Google::Protobuf::Compiler::CodeGeneratorResponse
Run protoc generation.
Instance Method Summary collapse
-
#initialize(request) ⇒ Runner
constructor
Initializes the runner.
-
#run(generator_type: nil) ⇒ Google::Protobuf::Compiler::CodeGeneratorResponse
Run protoc generation.
Constructor Details
#initialize(request) ⇒ Runner
Initializes the runner.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
26 27 28 |
# File 'lib/gapic/runner.rb', line 26 def request @request end |
Class Method Details
.run(request, generator: nil) ⇒ Google::Protobuf::Compiler::CodeGeneratorResponse
Run protoc generation.
77 78 79 |
# File 'lib/gapic/runner.rb', line 77 def self.run request, generator: nil new(request).run generator_type: generator end |
Instance Method Details
#run(generator_type: nil) ⇒ Google::Protobuf::Compiler::CodeGeneratorResponse
Run protoc generation.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# 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 |