Class: FileDescriptorToRuby
- Inherits:
-
Struct
- Object
- Struct
- FileDescriptorToRuby
- Defined in:
- lib/protocol_buffers/compiler/file_descriptor_to_ruby.rb
Constant Summary
Constants included from FieldDescriptorProto::Label
FieldDescriptorProto::Label::LABEL_OPTIONAL, FieldDescriptorProto::Label::LABEL_REPEATED, FieldDescriptorProto::Label::LABEL_REQUIRED
Constants included from FieldDescriptorProto::Type
FieldDescriptorProto::Type::TYPE_BOOL, FieldDescriptorProto::Type::TYPE_BYTES, FieldDescriptorProto::Type::TYPE_DOUBLE, FieldDescriptorProto::Type::TYPE_ENUM, FieldDescriptorProto::Type::TYPE_FIXED32, FieldDescriptorProto::Type::TYPE_FIXED64, FieldDescriptorProto::Type::TYPE_FLOAT, FieldDescriptorProto::Type::TYPE_GROUP, FieldDescriptorProto::Type::TYPE_INT32, FieldDescriptorProto::Type::TYPE_INT64, FieldDescriptorProto::Type::TYPE_MESSAGE, FieldDescriptorProto::Type::TYPE_SFIXED32, FieldDescriptorProto::Type::TYPE_SFIXED64, FieldDescriptorProto::Type::TYPE_SINT32, FieldDescriptorProto::Type::TYPE_SINT64, FieldDescriptorProto::Type::TYPE_STRING, FieldDescriptorProto::Type::TYPE_UINT32, FieldDescriptorProto::Type::TYPE_UINT64
Instance Attribute Summary collapse
-
#descriptor ⇒ Object
Returns the value of attribute descriptor.
Instance Method Summary collapse
-
#initialize(descriptor) ⇒ FileDescriptorToRuby
constructor
A new instance of FileDescriptorToRuby.
- #write(io) ⇒ Object
Constructor Details
#initialize(descriptor) ⇒ FileDescriptorToRuby
Returns a new instance of FileDescriptorToRuby.
9 10 11 12 13 |
# File 'lib/protocol_buffers/compiler/file_descriptor_to_ruby.rb', line 9 def initialize(descriptor) super @package_modules = descriptor.package ? descriptor.package.split('.') : [] @ns = [] end |
Instance Attribute Details
#descriptor ⇒ Object
Returns the value of attribute descriptor
4 5 6 |
# File 'lib/protocol_buffers/compiler/file_descriptor_to_ruby.rb', line 4 def descriptor @descriptor end |
Instance Method Details
#write(io) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/protocol_buffers/compiler/file_descriptor_to_ruby.rb', line 15 def write(io) @io = io @io.write "#!/usr/bin/env ruby\n# Generated by the protocol buffer compiler. DO NOT EDIT!\n\nrequire 'protocol_buffers'\n\n" descriptor.dependency.each do |dep| dir = File.dirname(dep) filename = File.basename(dep, ".proto") + ".pb" path = if dir == '.' filename else File.join(dir, filename) end @io.write("begin; require '#{path}'; rescue LoadError; end\n") end @io.write("\n") unless descriptor.dependency.empty? in_namespace("module", @package_modules) do declare(descriptor., descriptor.enum_type) descriptor..each do || () end end end |