module Prototok::Utils::Protoc
Public Class Methods
cache()
click to toggle source
# File lib/prototok/utils/protoc.rb, line 8 def cache @cache ||= Set.new end
process(path)
click to toggle source
# File lib/prototok/utils/protoc.rb, line 12 def process(path) path = File.expand_path path if !path || !File.exist?(path) raise ArgumentError, 'protobuf proto file is missing' end input = File.read(path) digest = Digest::SHA256.hexdigest(input) if cache.include? digest false else temp = ::Tempfile.new digest temp.write input temp.rewind load_proto temp, digest end end
Private Class Methods
load_proto(proto, digest)
click to toggle source
# File lib/prototok/utils/protoc.rb, line 31 def load_proto(proto, digest) dirname = File.dirname(proto.path) output_rb = proto.path + '_pb.rb' protoc_command = "grpc_tools_ruby_protoc #{proto.path} --ruby_out=#{dirname} --proto_path=#{dirname}" success = system(protoc_command) Prototok.err(Errors::ExternalError, :external_command, 'protoc', protoc_command) unless success load output_rb cache.add digest end