class ProtobufDescriptor::FileDescriptor
Describes a complete .proto file.
See {FileDescriptorProto
}
Attributes
List of the enum types that are defined at the top level of this file, as a NamedCollection
of {ProtobufDescriptor::EnumDescriptor}
List of the enum types that are defined at the top level of this file, as a NamedCollection
of {ProtobufDescriptor::EnumDescriptor}
List of the enum types that are defined at the top level of this file, as a NamedCollection
of {ProtobufDescriptor::EnumDescriptor}
The FileDescriptorProto
this FileDescriptor
is wrapping.
The parent {ProtobufDescriptor}
List of the message types that are defined at the top level of this file, as a NamedCollection
of {ProtobufDescriptor::MessageDescriptor}
List of the message types that are defined at the top level of this file, as a NamedCollection
of {ProtobufDescriptor::MessageDescriptor}
List of the message types that are defined at the top level of this file, as a NamedCollection
of {ProtobufDescriptor::MessageDescriptor}
The parent {ProtobufDescriptor}
List of the services that are defined at the top level of this file, as a NamedCollection
of {ProtobufDescriptor::ServiceDescriptor}
List of the services that are defined at the top level of this file, as a NamedCollection
of {ProtobufDescriptor::ServiceDescriptor}
Public Instance Methods
Returns the fully qualified Java class name.
# File lib/protobuf_descriptor/file_descriptor.rb, line 112 def fully_qualified_java_name return [ present?(java_package) ? java_package : nil, present?(java_outer_classname) ? java_outer_classname : nil ].compact.join('.') end
Returns the fully qualified name, as used by the resolve_type
methods.
# File lib/protobuf_descriptor/file_descriptor.rb, line 107 def fully_qualified_name return ".#{self.package}" end
Returns the fully qualified Ruby class name as generated by various protobuf gems.
# File lib/protobuf_descriptor/file_descriptor.rb, line 128 def fully_qualified_ruby_name return "::#{self.package.gsub('.', '::')}" end
Returns the fully qualified Java name as Wire would generate it. Wire never wraps the definitions in a class named after the .proto file (essentially behaving as if java_outer_classname
were always true)
# File lib/protobuf_descriptor/file_descriptor.rb, line 122 def fully_qualified_wire_name return java_package end
Whether source code info is associated with this descriptor
# File lib/protobuf_descriptor/file_descriptor.rb, line 59 def has_source_code_info? file_descriptor_proto.has_field?(:source_code_info) end
If set, all the classes from the .proto file are wrapped in a single outer class with the given name. This applies to both Proto1 (equivalent to the old “–one_java_file” option) and Proto2 (where a .proto always translates to a single class, but you may want to explicitly choose the class name).
# File lib/protobuf_descriptor/file_descriptor.rb, line 94 def java_outer_classname if file_descriptor_proto.has_field?(:options) && present?(file_descriptor_proto.options.java_multiple_files) return nil elsif file_descriptor_proto.has_field?(:options) && present?(file_descriptor_proto.options.java_outer_classname) return file_descriptor_proto.options.java_outer_classname else basename = name.split('/').last basename = basename.gsub('.proto', '') return camelize(basename) end end
The Java package where classes generated from this .proto will be placed. By default, the proto package is used, but this is often inappropriate because proto packages do not normally start with backwards domain names.
# File lib/protobuf_descriptor/file_descriptor.rb, line 81 def java_package if file_descriptor_proto.has_field?(:options) && present?(file_descriptor_proto.options.java_package) return file_descriptor_proto.options.java_package else return file_descriptor_proto.package end end
Filename relative to root of source tree.
# File lib/protobuf_descriptor/file_descriptor.rb, line 68 def name file_descriptor_proto.name end
The package name defined by the .proto file. E.G. “foo”, “foo.bar”, etc.
# File lib/protobuf_descriptor/file_descriptor.rb, line 73 def package file_descriptor_proto.package end
# File lib/protobuf_descriptor/file_descriptor.rb, line 63 def source_code_info file_descriptor_proto.source_code_info end
Private Instance Methods
# File lib/protobuf_descriptor/file_descriptor.rb, line 138 def blank?(string) string.respond_to?(:empty?) ? !!string.empty? : !string end
# File lib/protobuf_descriptor/file_descriptor.rb, line 142 def camelize(string) if string.respond_to?(:camelize) return string.camelize else return string.split("_").map { |s| s.capitalize }.join("") end end
Copy over a bunch of methods that are normally part of active_support:
# File lib/protobuf_descriptor/file_descriptor.rb, line 134 def present?(string) return !blank?(string) end