Module: ProtobufDescriptor::HasChildren

Included in:
EnumDescriptor, FileDescriptor, MessageDescriptor, ServiceDescriptor
Defined in:
lib/protobuf_descriptor/has_children.rb

Overview

Mixin module to support classes with different "kinds" of children

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/protobuf_descriptor/has_children.rb', line 4

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#compute_source_code_info_path_component(child) ⇒ Object

Computes the "relative path" from this node to one of its direct children according to the rules specified by descriptor.proto line 506.



39
40
41
42
43
44
45
46
47
# File 'lib/protobuf_descriptor/has_children.rb', line 39

def compute_source_code_info_path_component(child)
  self.class.registered_children.each do |kind_id, collection|
    idx = self.send(collection).find_index(child)
    if !idx.nil?
      return [kind_id, idx]
    end
  end
  raise "Could not find #{child} in #{self}"
end

#named_childrenObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/protobuf_descriptor/has_children.rb', line 21

def named_children
  return @named_children if @named_children

  @named_children = NamedCollection.new([])

  self.class.registered_children.each do |id, method|
    collection = self.send(method)
    collection = collection.is_a?(NamedCollection) ? collection.collection : collection
    collection.each do |m|
      @named_children << m if m.is_a?(NamedChild)
    end
  end
  return @named_children
end