Class: Protobuf::CodeGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/protobuf/code_generator.rb

Constant Summary collapse

CodeGeneratorFatalError =
Class.new(RuntimeError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_bytes) ⇒ CodeGenerator

Returns a new instance of CodeGenerator.



28
29
30
31
# File 'lib/protobuf/code_generator.rb', line 28

def initialize(request_bytes)
  @request_bytes = request_bytes
  self.request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.decode(request_bytes)
end

Class Method Details

.fatal(message) ⇒ Object



9
10
11
# File 'lib/protobuf/code_generator.rb', line 9

def self.fatal(message)
  fail CodeGeneratorFatalError, message
end

rubocop:disable Lint/DuplicateMethods, Lint/NestedMethodDefinition



15
16
17
18
# File 'lib/protobuf/code_generator.rb', line 15

def self.print_tag_warning_suppress
  STDERR.puts "Suppress tag warning output with PB_NO_TAG_WARNINGS=1."
  def self.print_tag_warning_suppress; end # rubocop:disable Lint/DuplicateMethods, Lint/NestedMethodDefinition
end

.warn(message) ⇒ Object



18
19
20
# File 'lib/protobuf/code_generator.rb', line 18

def self.warn(message)
  STDERR.puts("[WARN] #{message}")
end

Instance Method Details

#eval_unknown_extensions!Object



33
34
35
36
37
38
# File 'lib/protobuf/code_generator.rb', line 33

def eval_unknown_extensions!
  request.proto_file.each do |file_descriptor|
    ::Protobuf::Generators::FileGenerator.new(file_descriptor).eval_unknown_extensions!
  end
  self.request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.decode(@request_bytes)
end

#generate_file(file_descriptor) ⇒ Object



40
41
42
# File 'lib/protobuf/code_generator.rb', line 40

def generate_file(file_descriptor)
  ::Protobuf::Generators::FileGenerator.new(file_descriptor).generate_output_file
end

#response_bytesObject



44
45
46
47
48
49
50
# File 'lib/protobuf/code_generator.rb', line 44

def response_bytes
  generated_files = request.proto_file.map do |file_descriptor|
    generate_file(file_descriptor)
  end

  ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => generated_files)
end