Sha256: 1e053b0f2b4f4c0cbc4c5a452f767703175b3d2d2081fc0ac6f0522fa7017a73

Contents?: true

Size: 1.5 KB

Versions: 45

Compression:

Stored size: 1.5 KB

Contents

require 'protobuf/generators/base'
require 'protobuf/generators/option_generator'

module Protobuf
  module Generators
    class ServiceGenerator < Base

      def compile
        run_once(:compile) do
          print_class(descriptor.name, :service) do
            print OptionGenerator.new(descriptor.options, current_indent).to_s if descriptor.options
            descriptor.method.each do |method_descriptor|
              print_method(method_descriptor)
            end
          end
        end
      end

      private

      def print_method(method_descriptor)
        request_klass = modulize(method_descriptor.input_type)
        response_klass = modulize(method_descriptor.output_type)
        name = ENV.key?('PB_USE_RAW_RPC_NAMES') ? method_descriptor.name : method_descriptor.name.underscore
        options = {}
        if method_descriptor.options
          method_descriptor.options.each_field do |field_option|
            option_value = method_descriptor.options[field_option.name]
            next unless method_descriptor.options.field?(field_option.name)
            options[field_option.fully_qualified_name] = serialize_value(option_value)
          end
        end

        rpc = "rpc :#{name}, #{request_klass}, #{response_klass}"

        if options.empty?
          puts rpc
          return
        end

        puts rpc + " do"
        options.each do |option_name, value|
          indent { puts "set_option #{option_name.inspect}, #{value}" }
        end
        puts "end"
      end

    end
  end
end

Version data entries

45 entries across 45 versions & 3 rubygems

Version Path
protobuf-3.10.9 lib/protobuf/generators/service_generator.rb
protobuf-3.10.8 lib/protobuf/generators/service_generator.rb
contrast-agent-6.7.0 lib/protobuf/generators/service_generator.rb
protobuf-3.10.7 lib/protobuf/generators/service_generator.rb
contrast-agent-6.6.5 lib/protobuf/generators/service_generator.rb
contrast-agent-6.6.4 lib/protobuf/generators/service_generator.rb
contrast-agent-6.6.3 lib/protobuf/generators/service_generator.rb
contrast-agent-6.6.2 lib/protobuf/generators/service_generator.rb
contrast-agent-6.6.1 lib/protobuf/generators/service_generator.rb
contrast-agent-6.6.0 lib/protobuf/generators/service_generator.rb
contrast-agent-6.5.1 lib/protobuf/generators/service_generator.rb
contrast-agent-6.5.0 lib/protobuf/generators/service_generator.rb
contrast-agent-6.4.0 lib/protobuf/generators/service_generator.rb
protobuf-3.10.6 lib/protobuf/generators/service_generator.rb
protobuf-3.10.5 lib/protobuf/generators/service_generator.rb
protobuf-3.10.4 lib/protobuf/generators/service_generator.rb
protobuf-cucumber-3.10.8 lib/protobuf/generators/service_generator.rb
protobuf-cucumber-3.10.7 lib/protobuf/generators/service_generator.rb
protobuf-cucumber-3.10.6 lib/protobuf/generators/service_generator.rb
protobuf-cucumber-3.10.5 lib/protobuf/generators/service_generator.rb