Class: ProtoPlugin::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/proto_plugin/context.rb

Overview

An object that is responsible for organizing the graph of imported descriptors for a given invocation of a plugin.

It provides many helpers for looking up a file, message, or other descriptor.

Instance Method Summary collapse

Constructor Details

#initialize(request:) ⇒ Context

Initializes a context from a given Google::Protobuf::Compiler::CodeGeneratorRequest.



10
11
12
13
# File 'lib/proto_plugin/context.rb', line 10

def initialize(request:)
  index_files_by_filename(request.proto_file)
  index_types_by_proto_name
end

Instance Method Details

#file_by_filename(name) ⇒ ProtoPlugin::FileDescriptor?

Finds an imported file descriptor with the given name attribute.

Returns:



19
20
21
# File 'lib/proto_plugin/context.rb', line 19

def file_by_filename(name)
  @files_by_filename[name]
end

#type_by_proto_name(name) ⇒ Object



23
24
25
# File 'lib/proto_plugin/context.rb', line 23

def type_by_proto_name(name)
  @types_by_proto_name[name]
end