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(context, 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(context, descriptor) ⇒ FileDescriptor
Returns a new instance of FileDescriptor.
19 20 21 22 23 |
# File 'lib/proto_plugin/file_descriptor.rb', line 19 def initialize(context, descriptor) super(descriptor) @context = context @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.
31 32 33 34 35 |
# File 'lib/proto_plugin/file_descriptor.rb', line 31 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.
43 44 45 46 47 |
# File 'lib/proto_plugin/file_descriptor.rb', line 43 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.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/proto_plugin/file_descriptor.rb', line 64 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.
83 84 85 86 87 |
# File 'lib/proto_plugin/file_descriptor.rb', line 83 def services @services ||= @descriptor.service.map do |s| ServiceDescriptor.new(s, self, @context) end end |