Class: ProtoPlugin::FileDescriptor
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ProtoPlugin::FileDescriptor
- Defined in:
- lib/proto_plugin/file_descriptor.rb
Overview
A wrapper class around Google::Protobuf::FileDescriptorProto
which provides helpers and more idiomatic Ruby access patterns.
Any method not defined directly is delegated to the descriptor the wrapper was initialized with.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#enums ⇒ Array<EnumDescriptor>
The enums defined as children of this file.
-
#initialize(descriptor) ⇒ FileDescriptor
constructor
A new instance of FileDescriptor.
-
#messages ⇒ Array<MessageDescriptor>
The messages defined as children of this file.
-
#namespace(split: false) ⇒ String+
Returns the Ruby namespace (module) for the file.
-
#services ⇒ Array<ServiceDescriptor>
The services defined in this file.
Constructor Details
#initialize(descriptor) ⇒ FileDescriptor
Returns a new instance of FileDescriptor.
18 19 20 21 |
# File 'lib/proto_plugin/file_descriptor.rb', line 18 def initialize(descriptor) super @descriptor = descriptor end |
Instance Attribute Details
#descriptor ⇒ Google::Protobuf::FileDescriptorProto (readonly)
15 16 17 |
# File 'lib/proto_plugin/file_descriptor.rb', line 15 def descriptor @descriptor end |
Instance Method Details
#enums ⇒ Array<EnumDescriptor>
The enums defined as children of this file.
29 30 31 32 33 |
# File 'lib/proto_plugin/file_descriptor.rb', line 29 def enums @enums ||= @descriptor.enum_type.map do |e| EnumDescriptor.new(e, self) end end |
#messages ⇒ Array<MessageDescriptor>
The messages defined as children of this file.
41 42 43 44 45 |
# File 'lib/proto_plugin/file_descriptor.rb', line 41 def @messages ||= @descriptor..map do |m| MessageDescriptor.new(m, self) end end |
#namespace(split: false) ⇒ String+
Returns the Ruby namespace (module) for the file.
If the ruby_package
option was specified, then that value is returned directly. Otherwise, the package
value is transformed to Ruby module notation.
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/proto_plugin/file_descriptor.rb', line 62 def namespace(split: false) @namespace ||= begin namespace = @descriptor.&.ruby_package if !namespace || namespace.empty? namespace = @descriptor.package.split(".") .map { |token| Utils.camelize(token) } .join("::") end namespace end split ? @namespace.split("::") : @namespace end |
#services ⇒ Array<ServiceDescriptor>
The services defined in this file.
81 82 83 84 85 |
# File 'lib/proto_plugin/file_descriptor.rb', line 81 def services @services ||= @descriptor.service.map do |s| ServiceDescriptor.new(s, self) end end |