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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/protod/proto/builder.rb', line 19
def build
return if @root_package.built?
handler = Protod::Rpc::Handler.build_in(@root_package)
@receivers.keys.each do |receiver|
package = Protod.find_or_register_package("#{@root_package.full_ident}.#{receiver.underscore.gsub('/', '.')}")
request_field = Protod::Proto::Field.build_from(Protod::Rpc::Request.find_by(receiver), ident: receiver)
response_field = Protod::Proto::Field.build_from(Protod::Rpc::Response.find_by(receiver), ident: receiver)
handler.register_receiver(request_field, response_field)
request_message = package.bind(request_field.interpreter)
response_message = package.bind(response_field.interpreter)
bindable_interpreters_under(request_message, response_message).each do |i|
root_message_name = i.const.ruby_ident.singleton ? 'Singleton' : 'Instance'
package
.find_or_push(root_message_name, by: :ident, into: :messages)
.find_or_push(i.const.ruby_ident.method_name, by: :ident, into: :messages)
.bind(i)
end
end
models_package = Protod.find_or_register_package("#{@root_package.full_ident}.models")
while (interpreters = bindable_interpreters_under(*@root_package.all_packages)).present?
interpreters.each { models_package.bind(_1) }
end
any_interpreter = Protod::Interpreter.find_by('RBS::Types::Bases::Any')
if @root_package.all_packages.flat_map(&:collect_fields).any? { _1.interpreter == any_interpreter }
i = Protod::Interpreter.find_by('Array')
models_package.bind(i) if i.bindable?
models_package.imports.push(Protod::Interpreter.find_by('Hash').proto_path)
end
end
|