Class: Protobuf::Visitor::CreateRpcVisitor
- Defined in:
- lib/protobuf/compiler/visitors.rb
Instance Attribute Summary collapse
-
#current_service ⇒ Object
Returns the value of attribute current_service.
-
#file_contents ⇒ Object
Returns the value of attribute file_contents.
-
#package ⇒ Object
Returns the value of attribute package.
-
#services ⇒ Object
Returns the value of attribute services.
Attributes inherited from Base
Instance Method Summary collapse
- #add_rpc(name, request, response) ⇒ Object
- #create_files(message_file, out_dir, create_file = true) ⇒ Object
- #create_service(message_file, out_dir, underscored_name, module_name, service_name, default_port, rpcs, required_file) ⇒ Object
-
#initialize ⇒ CreateRpcVisitor
constructor
A new instance of CreateRpcVisitor.
- #visit(node) ⇒ Object
Methods inherited from Base
#create_file_with_backup, #log_writing
Constructor Details
#initialize ⇒ CreateRpcVisitor
Returns a new instance of CreateRpcVisitor.
139 140 141 142 143 |
# File 'lib/protobuf/compiler/visitors.rb', line 139 def initialize @services = {} @create_file = true @file_contents = {} end |
Instance Attribute Details
#current_service ⇒ Object
Returns the value of attribute current_service.
137 138 139 |
# File 'lib/protobuf/compiler/visitors.rb', line 137 def current_service @current_service end |
#file_contents ⇒ Object
Returns the value of attribute file_contents.
137 138 139 |
# File 'lib/protobuf/compiler/visitors.rb', line 137 def file_contents @file_contents end |
#package ⇒ Object
Returns the value of attribute package.
137 138 139 |
# File 'lib/protobuf/compiler/visitors.rb', line 137 def package @package end |
#services ⇒ Object
Returns the value of attribute services.
137 138 139 |
# File 'lib/protobuf/compiler/visitors.rb', line 137 def services @services end |
Instance Method Details
#add_rpc(name, request, response) ⇒ Object
150 151 152 |
# File 'lib/protobuf/compiler/visitors.rb', line 150 def add_rpc(name, request, response) (@services[@current_service] ||= []) << [name, Util.moduleize(request), Util.moduleize(response)] end |
#create_files(message_file, out_dir, create_file = true) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/protobuf/compiler/visitors.rb', line 154 def create_files(, out_dir, create_file=true) @create_file = create_file default_port = 9999 @services.each do |service_name, rpcs| underscored_name = underscore service_name.to_s = package.map{|p| p.to_s.capitalize}.join('::') required_file = [ Util.module_to_path(), File.basename(.sub(/^\.\//, '').sub(/\.rb$/, '')) ].join('/').gsub(/\/{2,}/, '/') create_service(, out_dir, underscored_name, , service_name, default_port, rpcs, required_file) end @file_contents end |
#create_service(message_file, out_dir, underscored_name, module_name, service_name, default_port, rpcs, required_file) ⇒ Object
170 171 172 173 174 175 |
# File 'lib/protobuf/compiler/visitors.rb', line 170 def create_service(, out_dir, underscored_name, module_name, service_name, default_port, rpcs, required_file) service_filename = "#{out_dir}/#{Util.module_to_path(module_name)}/#{underscored_name}.rb" service_contents = template_erb('rpc_service_implementation').result(binding) create_file_with_backup(service_filename, service_contents) if @create_file @file_contents[service_filename] = service_contents end |
#visit(node) ⇒ Object
145 146 147 148 |
# File 'lib/protobuf/compiler/visitors.rb', line 145 def visit(node) node.accept_rpc_visitor(self) self end |