Class: ProtoPlugin::EnumDescriptor

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

Methods included from Commentable

#comments, #leading_comments, #source_location, #trailing_comments

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.



27
28
29
30
31
# File 'lib/proto_plugin/enum_descriptor.rb', line 27

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

Instance Attribute Details

#descriptorGoogle::Protobuf::EnumDescriptorProto (readonly)

Returns:

  • (Google::Protobuf::EnumDescriptorProto)


16
17
18
# File 'lib/proto_plugin/enum_descriptor.rb', line 16

def descriptor
  @descriptor
end

#parentFileDescriptor, MessageDescriptor (readonly)

The file or message descriptor this enum was defined within.

Returns:



22
23
24
# File 'lib/proto_plugin/enum_descriptor.rb', line 22

def parent
  @parent
end

Instance Method Details

#fileFileDescriptor

The file descriptor this enum belongs to.

Returns:



36
37
38
# File 'lib/proto_plugin/enum_descriptor.rb', line 36

def file
  parent.file
end

#full_nameString

The full name of the enum, including parent namespace.

Examples:

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

Returns:

  • (String)


58
59
60
61
62
63
64
65
66
67
68
# File 'lib/proto_plugin/enum_descriptor.rb', line 58

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

#valuesArray<EnumValueDescriptor>

The values defined for this enum.



46
47
48
49
50
# File 'lib/proto_plugin/enum_descriptor.rb', line 46

def values
  @values ||= @descriptor.value.map do |v|
    EnumValueDescriptor.new(v, self)
  end
end