Class: ProtoPlugin::EnumDescriptor

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

Overview

A wrapper class around Google::Protobuf::EnumDescriptorProto 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) ⇒ EnumDescriptor

Returns a new instance of EnumDescriptor.

Parameters:

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

    The file or message descriptor this enum was defined within.



25
26
27
28
29
# File 'lib/proto_plugin/enum_descriptor.rb', line 25

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

Instance Attribute Details

#descriptorGoogle::Protobuf::EnumDescriptorProto (readonly)

Returns:

  • (Google::Protobuf::EnumDescriptorProto)


14
15
16
# File 'lib/proto_plugin/enum_descriptor.rb', line 14

def descriptor
  @descriptor
end

#parentFileDescriptor, MessageDescriptor (readonly)

The file or message descriptor this enum was defined within.

Returns:



20
21
22
# File 'lib/proto_plugin/enum_descriptor.rb', line 20

def parent
  @parent
end

Instance Method Details

#full_nameString

The full name of the enum, including parent namespace.

Examples:

"My::Ruby::Package::EnumName"

Returns:

  • (String)


37
38
39
40
41
42
43
44
45
46
47
# File 'lib/proto_plugin/enum_descriptor.rb', line 37

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