class ProtobufDescriptor::FileDescriptor

Describes a complete .proto file.

See {FileDescriptorProto}

Attributes

enum_type[R]

List of the enum types that are defined at the top level of this file, as a NamedCollection of {ProtobufDescriptor::EnumDescriptor}

enum_types[R]

List of the enum types that are defined at the top level of this file, as a NamedCollection of {ProtobufDescriptor::EnumDescriptor}

enums[R]

List of the enum types that are defined at the top level of this file, as a NamedCollection of {ProtobufDescriptor::EnumDescriptor}

file_descriptor_proto[R]

The FileDescriptorProto this FileDescriptor is wrapping.

file_descriptor_set[R]

The parent {ProtobufDescriptor}

message_type[R]

List of the message types that are defined at the top level of this file, as a NamedCollection of {ProtobufDescriptor::MessageDescriptor}

message_types[R]

List of the message types that are defined at the top level of this file, as a NamedCollection of {ProtobufDescriptor::MessageDescriptor}

messages[R]

List of the message types that are defined at the top level of this file, as a NamedCollection of {ProtobufDescriptor::MessageDescriptor}

parent[R]

The parent {ProtobufDescriptor}

service[R]

List of the services that are defined at the top level of this file, as a NamedCollection of {ProtobufDescriptor::ServiceDescriptor}

services[R]

List of the services that are defined at the top level of this file, as a NamedCollection of {ProtobufDescriptor::ServiceDescriptor}

Public Instance Methods

fully_qualified_java_name() click to toggle source

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

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

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

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
has_source_code_info?() click to toggle source

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

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

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

Filename relative to root of source tree.

# File lib/protobuf_descriptor/file_descriptor.rb, line 68
def name
  file_descriptor_proto.name
end
package() click to toggle source

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
source_code_info() click to toggle source
# File lib/protobuf_descriptor/file_descriptor.rb, line 63
def source_code_info
  file_descriptor_proto.source_code_info
end

Private Instance Methods

blank?(string) click to toggle source
# File lib/protobuf_descriptor/file_descriptor.rb, line 138
def blank?(string)
  string.respond_to?(:empty?) ? !!string.empty? : !string
end
camelize(string) click to toggle source
# 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
present?(string) click to toggle source

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