Class: ProtoPlugin::MessageDescriptor
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ProtoPlugin::MessageDescriptor
- Includes:
- Commentable
- Defined in:
- lib/proto_plugin/message_descriptor.rb
Overview
A wrapper class around Google::Protobuf::DescriptorProto which provides helpers and more idiomatic Ruby access patterns.
Any method not defined directly is delegated to the descriptor the wrapper was initialized with.
Instance Attribute Summary collapse
- #descriptor ⇒ Google::Protobuf::DescriptorProto readonly
-
#parent ⇒ FileDescriptor, MessageDescriptor
readonly
The file or message descriptor this message was defined within.
Instance Method Summary collapse
-
#enums ⇒ Array<EnumDescriptor>
The enums defined as children of this message.
-
#fields ⇒ Array<FieldDescriptor>
The fields defined on this message.
-
#file ⇒ FileDescriptor
The file descriptor this message belongs to.
-
#full_name ⇒ String
The full name of the message, including parent namespace.
-
#initialize(descriptor, parent, context) ⇒ MessageDescriptor
constructor
A new instance of MessageDescriptor.
-
#messages ⇒ Array<MessageDescriptor>
The messages defined as children of this message.
-
#oneofs ⇒ Array<OneofDescriptor>
The oneofs defined on this message.
Methods included from Commentable
#comments, #leading_comments, #source_location, #trailing_comments
Constructor Details
#initialize(descriptor, parent, context) ⇒ MessageDescriptor
Returns a new instance of MessageDescriptor.
29 30 31 32 33 34 |
# File 'lib/proto_plugin/message_descriptor.rb', line 29 def initialize(descriptor, parent, context) super(descriptor) @descriptor = descriptor @parent = parent @context = context end |
Instance Attribute Details
#descriptor ⇒ Google::Protobuf::DescriptorProto (readonly)
17 18 19 |
# File 'lib/proto_plugin/message_descriptor.rb', line 17 def descriptor @descriptor end |
#parent ⇒ FileDescriptor, MessageDescriptor (readonly)
The file or message descriptor this message was defined within.
23 24 25 |
# File 'lib/proto_plugin/message_descriptor.rb', line 23 def parent @parent end |
Instance Method Details
#enums ⇒ Array<EnumDescriptor>
The enums defined as children of this message.
73 74 75 76 77 |
# File 'lib/proto_plugin/message_descriptor.rb', line 73 def enums @enums ||= @descriptor.enum_type.map do |e| EnumDescriptor.new(e, self) end end |
#fields ⇒ Array<FieldDescriptor>
The fields defined on this message.
49 50 51 52 53 |
# File 'lib/proto_plugin/message_descriptor.rb', line 49 def fields @fields ||= @descriptor.field.map do |f| FieldDescriptor.new(f, self, @context) end end |
#file ⇒ FileDescriptor
The file descriptor this message belongs to.
39 40 41 |
# File 'lib/proto_plugin/message_descriptor.rb', line 39 def file parent.file end |
#full_name ⇒ String
The full name of the message, including parent namespace.
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/proto_plugin/message_descriptor.rb', line 101 def full_name @full_name ||= begin prefix = case parent when MessageDescriptor parent.full_name when FileDescriptor parent.namespace end "#{prefix}::#{name}" end end |
#messages ⇒ Array<MessageDescriptor>
The messages defined as children of this message.
Synthetic map-entry types (generated by protoc to back map<K, V> fields) are excluded, as they are an implementation detail rather than user-declared messages. Use FieldDescriptor#map? to work with maps.
89 90 91 92 93 |
# File 'lib/proto_plugin/message_descriptor.rb', line 89 def @nested_messages ||= @descriptor.nested_type.reject { |m| m.&.map_entry }.map do |m| MessageDescriptor.new(m, self, @context) end end |
#oneofs ⇒ Array<OneofDescriptor>
The oneofs defined on this message.
61 62 63 64 65 |
# File 'lib/proto_plugin/message_descriptor.rb', line 61 def oneofs @oneofs ||= @descriptor.oneof_decl.each_with_index.map do |o, i| OneofDescriptor.new(o, self, i) end end |