module ProtobufDescriptor::HasChildren

Mixin module to support classes with different “kinds” of children

Public Class Methods

included(base) click to toggle source
# File lib/protobuf_descriptor/has_children.rb, line 4
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

compute_source_code_info_path_component(child) click to toggle source

Computes the “relative path” from this node to one of its direct children according to the rules specified by [descriptor.proto line 506](code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/descriptor.proto#506).

# 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_children() click to toggle source
# 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