Class: ProtoPlugin::OneofDescriptor

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Commentable
Defined in:
lib/proto_plugin/oneof_descriptor.rb

Overview

A wrapper class around Google::Protobuf::OneofDescriptorProto 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, message, index) ⇒ OneofDescriptor

Returns a new instance of OneofDescriptor.

Parameters:

  • descriptor (Google::Protobuf::OneofDescriptorProto)
  • message (MessageDescriptor)

    The message this oneof was defined within.

  • index (Integer)

    The index of this oneof within the message.



32
33
34
35
36
37
# File 'lib/proto_plugin/oneof_descriptor.rb', line 32

def initialize(descriptor, message, index)
  super(descriptor)
  @descriptor = descriptor
  @message = message
  @index = index
end

Instance Attribute Details

#descriptorGoogle::Protobuf::OneofDescriptorProto (readonly)

Returns:

  • (Google::Protobuf::OneofDescriptorProto)


17
18
19
# File 'lib/proto_plugin/oneof_descriptor.rb', line 17

def descriptor
  @descriptor
end

#indexInteger (readonly)

The index of this oneof within its message’s oneof_decl list.

Returns:

  • (Integer)


27
28
29
# File 'lib/proto_plugin/oneof_descriptor.rb', line 27

def index
  @index
end

#messageMessageDescriptor (readonly)

The message descriptor this oneof was defined within.

Returns:



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

def message
  @message
end

Instance Method Details

#fieldsArray<FieldDescriptor>

The fields that are members of this oneof.

Returns:



49
50
51
52
53
# File 'lib/proto_plugin/oneof_descriptor.rb', line 49

def fields
  @fields ||= message.fields.select do |field|
    field.oneof? && field.oneof_index == index
  end
end

#fileFileDescriptor

The file descriptor this oneof belongs to.

Returns:



42
43
44
# File 'lib/proto_plugin/oneof_descriptor.rb', line 42

def file
  message.file
end