Class: ProtoPlugin::MessageDescriptor

Inherits:
SimpleDelegator
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(descriptor, parent) ⇒ MessageDescriptor

Returns a new instance of MessageDescriptor.

Parameters:

  • descriptor (Google::Protobuf::DescriptorProto)
  • parent (FileDescriptorFileDescriptorProto, MessageDescriptor)

    The file or message descriptor this message was defined within.



26
27
28
29
30
# File 'lib/proto_plugin/message_descriptor.rb', line 26

def initialize(descriptor, parent)
  super(descriptor)
  @descriptor = descriptor
  @parent = parent
end

Instance Attribute Details

#descriptorGoogle::Protobuf::DescriptorProto (readonly)

Returns:

  • (Google::Protobuf::DescriptorProto)


15
16
17
# File 'lib/proto_plugin/message_descriptor.rb', line 15

def descriptor
  @descriptor
end

#parentFileDescriptor, MessageDescriptor (readonly)

The file or message descriptor this message was defined within.

Returns:



21
22
23
# File 'lib/proto_plugin/message_descriptor.rb', line 21

def parent
  @parent
end

Instance Method Details

#enumsArray<EnumDescriptor>

The enums defined as children of this message.



38
39
40
41
42
# File 'lib/proto_plugin/message_descriptor.rb', line 38

def enums
  @enums ||= @descriptor.enum_type.map do |e|
    EnumDescriptor.new(e, self)
  end
end

#full_nameString

The full name of the message, including parent namespace.

Examples:

"My::Ruby::Package::MessageName"

Returns:

  • (String)


62
63
64
65
66
67
68
69
70
71
72
# File 'lib/proto_plugin/message_descriptor.rb', line 62

def full_name
  @full_name ||= begin
    prefix = case parent
    when MessageDescriptor
      parent.full_name
    when FileDescriptor
      parent.namespace
    end
    "#{prefix}::#{name}"
  end
end

#messagesArray<MessageDescriptor>

The messages defined as children of this message.



50
51
52
53
54
# File 'lib/proto_plugin/message_descriptor.rb', line 50

def messages
  @nested_messages ||= @descriptor.nested_type.map do |m|
    MessageDescriptor.new(m, self)
  end
end