Class: Protobuf::Node::MessageNode

Inherits:
Base
  • Object
show all
Defined in:
lib/protobuf/compiler/nodes.rb

Instance Method Summary collapse

Methods inherited from Base

#accept_rpc_visitor, #define_in_the_file

Constructor Details

#initialize(name, children) ⇒ MessageNode

Returns a new instance of MessageNode.



105
106
107
# File 'lib/protobuf/compiler/nodes.rb', line 105

def initialize(name, children)
  @name, @children = name, children
end

Instance Method Details

#accept_descriptor_visitor(visitor) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/protobuf/compiler/nodes.rb', line 120

def accept_descriptor_visitor(visitor)
  descriptor = Google::Protobuf::DescriptorProto.new(:name => @name.to_s)
  visitor.descriptor = descriptor
  visitor.in_context(descriptor) do
    @children.each {|child| child.accept_descriptor_visitor(visitor) }
  end
end

#accept_message_visitor(visitor) ⇒ Object



109
110
111
112
113
114
115
116
117
118
# File 'lib/protobuf/compiler/nodes.rb', line 109

def accept_message_visitor(visitor)
  class_name = @name.to_s
  class_name.gsub!(/\A[a-z]/) {|c| c.upcase}
  visitor.write("class #{class_name} < ::Protobuf::Message")
  visitor.in_context(self.class) do
    define_in_the_file(visitor)
    @children.each {|child| child.accept_message_visitor(visitor) }
  end
  visitor.write('end')
end