Module: ProtobufDescriptor::HasParent
- Included in:
- EnumDescriptor, EnumValueDescriptor, FieldDescriptor, MessageDescriptor, MethodDescriptor, ServiceDescriptor
- Defined in:
- lib/protobuf_descriptor/has_parent.rb
Overview
Mixin module to make accessing ancestors easier.
Also has a random method for computing the source code info path (as well as methods that rely on it to do things like grab comments and the like.)
Classes that include this module must respond_to parent
, in addition their
parent include HasChildren
Instance Method Summary collapse
- #compute_source_code_info_path ⇒ Object
- #file_descriptor ⇒ Object
- #leading_comments ⇒ Object
- #protobuf_descriptor ⇒ Object
- #source_code_info_location ⇒ Object
- #source_code_info_locations ⇒ Object
- #source_code_info_span ⇒ Object
- #trailing_comments ⇒ Object
Instance Method Details
#compute_source_code_info_path ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/protobuf_descriptor/has_parent.rb', line 26 def compute_source_code_info_path path_component = parent.compute_source_code_info_path_component(self) parent_path = if parent.class.name == "ProtobufDescriptor::FileDescriptor" [] else parent.compute_source_code_info_path end return parent_path + path_component end |
#file_descriptor ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/protobuf_descriptor/has_parent.rb', line 10 def file_descriptor p = self.parent while p.class.name != "ProtobufDescriptor::FileDescriptor" p = p.parent end return p end |
#leading_comments ⇒ Object
53 54 55 |
# File 'lib/protobuf_descriptor/has_parent.rb', line 53 def leading_comments return source_code_info_location.leading_comments end |
#protobuf_descriptor ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/protobuf_descriptor/has_parent.rb', line 18 def protobuf_descriptor p = self.parent while p.class.name != "ProtobufDescriptor" p = p.parent end return p end |
#source_code_info_location ⇒ Object
45 46 47 |
# File 'lib/protobuf_descriptor/has_parent.rb', line 45 def source_code_info_location return source_code_info_locations.first end |
#source_code_info_locations ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/protobuf_descriptor/has_parent.rb', line 36 def source_code_info_locations raise "No source code info attached!" unless file_descriptor.has_source_code_info? source_code_info_path = compute_source_code_info_path return file_descriptor.source_code_info.location.select { |location| location.path == source_code_info_path } end |
#source_code_info_span ⇒ Object
49 50 51 |
# File 'lib/protobuf_descriptor/has_parent.rb', line 49 def source_code_info_span return source_code_info_location.span end |
#trailing_comments ⇒ Object
57 58 59 |
# File 'lib/protobuf_descriptor/has_parent.rb', line 57 def trailing_comments return source_code_info_location.trailing_comments end |