protobuf 3.3.6 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +48 -0
  3. data/.rubocop_todo.yml +79 -0
  4. data/.travis.yml +12 -4
  5. data/Rakefile +14 -11
  6. data/bin/protoc-gen-ruby +0 -1
  7. data/bin/rpc_server +1 -0
  8. data/install-protobuf.sh +8 -0
  9. data/lib/protobuf.rb +30 -24
  10. data/lib/protobuf/cli.rb +35 -35
  11. data/lib/protobuf/code_generator.rb +11 -8
  12. data/lib/protobuf/decoder.rb +4 -5
  13. data/lib/protobuf/deprecation.rb +20 -0
  14. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +2 -0
  15. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +2 -0
  16. data/lib/protobuf/encoder.rb +9 -4
  17. data/lib/protobuf/enum.rb +38 -54
  18. data/lib/protobuf/field.rb +2 -2
  19. data/lib/protobuf/field/base_field.rb +28 -32
  20. data/lib/protobuf/field/bool_field.rb +4 -4
  21. data/lib/protobuf/field/bytes_field.rb +5 -4
  22. data/lib/protobuf/field/double_field.rb +0 -1
  23. data/lib/protobuf/field/enum_field.rb +4 -7
  24. data/lib/protobuf/field/field_array.rb +3 -4
  25. data/lib/protobuf/field/fixed32_field.rb +1 -1
  26. data/lib/protobuf/field/fixed64_field.rb +0 -1
  27. data/lib/protobuf/field/float_field.rb +0 -1
  28. data/lib/protobuf/field/int32_field.rb +0 -1
  29. data/lib/protobuf/field/int64_field.rb +0 -1
  30. data/lib/protobuf/field/integer_field.rb +0 -1
  31. data/lib/protobuf/field/message_field.rb +2 -3
  32. data/lib/protobuf/field/sfixed32_field.rb +0 -1
  33. data/lib/protobuf/field/sfixed64_field.rb +0 -1
  34. data/lib/protobuf/field/signed_integer_field.rb +0 -1
  35. data/lib/protobuf/field/sint32_field.rb +0 -1
  36. data/lib/protobuf/field/sint64_field.rb +0 -1
  37. data/lib/protobuf/field/string_field.rb +0 -1
  38. data/lib/protobuf/field/uint32_field.rb +0 -1
  39. data/lib/protobuf/field/uint64_field.rb +0 -1
  40. data/lib/protobuf/field/varint_field.rb +0 -1
  41. data/lib/protobuf/generators/base.rb +1 -2
  42. data/lib/protobuf/generators/enum_generator.rb +1 -2
  43. data/lib/protobuf/generators/extension_generator.rb +1 -2
  44. data/lib/protobuf/generators/field_generator.rb +4 -5
  45. data/lib/protobuf/generators/file_generator.rb +22 -27
  46. data/lib/protobuf/generators/group_generator.rb +15 -16
  47. data/lib/protobuf/generators/message_generator.rb +13 -14
  48. data/lib/protobuf/generators/printable.rb +9 -10
  49. data/lib/protobuf/generators/service_generator.rb +1 -2
  50. data/lib/protobuf/lifecycle.rb +20 -33
  51. data/lib/protobuf/logging.rb +4 -6
  52. data/lib/protobuf/message.rb +22 -16
  53. data/lib/protobuf/message/fields.rb +14 -17
  54. data/lib/protobuf/message/serialization.rb +6 -5
  55. data/lib/protobuf/rpc/buffer.rb +10 -12
  56. data/lib/protobuf/rpc/client.rb +12 -12
  57. data/lib/protobuf/rpc/connectors/base.rb +4 -3
  58. data/lib/protobuf/rpc/connectors/common.rb +15 -17
  59. data/lib/protobuf/rpc/connectors/socket.rb +2 -2
  60. data/lib/protobuf/rpc/connectors/zmq.rb +118 -108
  61. data/lib/protobuf/rpc/dynamic_discovery.pb.rb +2 -0
  62. data/lib/protobuf/rpc/env.rb +12 -12
  63. data/lib/protobuf/rpc/error.rb +1 -1
  64. data/lib/protobuf/rpc/error/client_error.rb +4 -4
  65. data/lib/protobuf/rpc/error/server_error.rb +6 -6
  66. data/lib/protobuf/rpc/middleware/exception_handler.rb +1 -1
  67. data/lib/protobuf/rpc/middleware/logger.rb +3 -3
  68. data/lib/protobuf/rpc/middleware/request_decoder.rb +5 -5
  69. data/lib/protobuf/rpc/middleware/response_encoder.rb +3 -3
  70. data/lib/protobuf/rpc/rpc.pb.rb +2 -0
  71. data/lib/protobuf/rpc/servers/socket/server.rb +75 -65
  72. data/lib/protobuf/rpc/servers/socket/worker.rb +2 -2
  73. data/lib/protobuf/rpc/servers/socket_runner.rb +12 -6
  74. data/lib/protobuf/rpc/servers/zmq/broker.rb +10 -6
  75. data/lib/protobuf/rpc/servers/zmq/server.rb +20 -26
  76. data/lib/protobuf/rpc/servers/zmq/util.rb +7 -7
  77. data/lib/protobuf/rpc/servers/zmq/worker.rb +5 -7
  78. data/lib/protobuf/rpc/servers/zmq_runner.rb +14 -3
  79. data/lib/protobuf/rpc/service.rb +15 -15
  80. data/lib/protobuf/rpc/service_directory.rb +7 -11
  81. data/lib/protobuf/rpc/service_dispatcher.rb +3 -3
  82. data/lib/protobuf/rpc/service_filters.rb +27 -28
  83. data/lib/protobuf/rpc/stat.rb +4 -7
  84. data/lib/protobuf/socket.rb +0 -1
  85. data/lib/protobuf/tasks/compile.rake +2 -2
  86. data/lib/protobuf/version.rb +1 -1
  87. data/protobuf.gemspec +20 -4
  88. data/spec/benchmark/tasks.rb +49 -23
  89. data/spec/bin/protoc-gen-ruby_spec.rb +11 -6
  90. data/spec/encoding/all_types_spec.rb +91 -77
  91. data/spec/encoding/extreme_values_spec.rb +0 -0
  92. data/spec/functional/socket_server_spec.rb +9 -10
  93. data/spec/functional/zmq_server_spec.rb +21 -19
  94. data/spec/lib/protobuf/cli_spec.rb +20 -20
  95. data/spec/lib/protobuf/code_generator_spec.rb +6 -6
  96. data/spec/lib/protobuf/enum_spec.rb +57 -31
  97. data/spec/lib/protobuf/field/float_field_spec.rb +2 -2
  98. data/spec/lib/protobuf/field/int32_field_spec.rb +1 -1
  99. data/spec/lib/protobuf/field/string_field_spec.rb +7 -8
  100. data/spec/lib/protobuf/field_spec.rb +3 -6
  101. data/spec/lib/protobuf/generators/base_spec.rb +6 -6
  102. data/spec/lib/protobuf/generators/enum_generator_spec.rb +22 -17
  103. data/spec/lib/protobuf/generators/extension_generator_spec.rb +8 -9
  104. data/spec/lib/protobuf/generators/field_generator_spec.rb +14 -11
  105. data/spec/lib/protobuf/generators/file_generator_spec.rb +7 -4
  106. data/spec/lib/protobuf/generators/service_generator_spec.rb +14 -11
  107. data/spec/lib/protobuf/lifecycle_spec.rb +9 -4
  108. data/spec/lib/protobuf/message_spec.rb +63 -35
  109. data/spec/lib/protobuf/optionable_spec.rb +3 -3
  110. data/spec/lib/protobuf/rpc/client_spec.rb +2 -2
  111. data/spec/lib/protobuf/rpc/connector_spec.rb +1 -1
  112. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +6 -6
  113. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +26 -18
  114. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +4 -4
  115. data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +11 -9
  116. data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +2 -2
  117. data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +7 -7
  118. data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +14 -14
  119. data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +5 -5
  120. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +1 -1
  121. data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +9 -7
  122. data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +9 -9
  123. data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +2 -2
  124. data/spec/lib/protobuf/rpc/service_directory_spec.rb +24 -23
  125. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +4 -4
  126. data/spec/lib/protobuf/rpc/service_filters_spec.rb +84 -51
  127. data/spec/lib/protobuf/rpc/service_spec.rb +15 -14
  128. data/spec/lib/protobuf/rpc/stat_spec.rb +1 -1
  129. data/spec/lib/protobuf_spec.rb +9 -9
  130. data/spec/spec_helper.rb +7 -19
  131. data/spec/support/server.rb +29 -59
  132. data/spec/support/test/defaults.pb.rb +2 -0
  133. data/spec/support/test/enum.pb.rb +2 -0
  134. data/spec/support/test/extended.pb.rb +2 -0
  135. data/spec/support/test/google_unittest_import.pb.rb +2 -0
  136. data/spec/support/test/google_unittest_import_public.pb.rb +2 -0
  137. data/spec/support/test/multi_field_extensions.pb.rb +2 -0
  138. data/spec/support/test/resource.pb.rb +2 -0
  139. data/spec/support/test/resource_service.rb +17 -20
  140. metadata +153 -112
  141. data/lib/protobuf/deprecator.rb +0 -42
@@ -12,7 +12,6 @@ module Protobuf
12
12
  false
13
13
  end
14
14
 
15
-
16
15
  ##
17
16
  # Public Instance Methods
18
17
  # #
@@ -39,15 +38,16 @@ module Protobuf
39
38
  super
40
39
 
41
40
  field = self
41
+ method_name = "#{field.getter}?"
42
+
42
43
  message_class.class_eval do
43
- define_method("#{field.getter}?") do
44
- field.warn_if_deprecated
44
+ define_method(method_name) do
45
45
  @values.fetch(field.name, field.default_value)
46
46
  end
47
+ ::Protobuf.deprecator.deprecate_methods(method_name)
47
48
  end
48
49
  end
49
50
 
50
51
  end
51
52
  end
52
53
  end
53
-
@@ -53,10 +53,11 @@ module Protobuf
53
53
 
54
54
  def define_setter
55
55
  field = self
56
+ method_name = field.setter
57
+
56
58
  message_class.class_eval do
57
- define_method(field.setter) do |val|
59
+ define_method(method_name) do |val|
58
60
  begin
59
- field.warn_if_deprecated
60
61
  val = "#{val}" if val.is_a?(Symbol)
61
62
 
62
63
  if val.nil?
@@ -64,7 +65,7 @@ module Protobuf
64
65
  elsif field.acceptable?(val)
65
66
  @values[field.name] = val.dup
66
67
  else
67
- raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}"
68
+ fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}"
68
69
  end
69
70
  rescue NoMethodError => ex
70
71
  logger.error { ex.message }
@@ -72,10 +73,10 @@ module Protobuf
72
73
  raise TypeError, "Got NoMethodError attempting to set #{val} for field #{field.name} of type #{field.type_class}: #{ex.message}"
73
74
  end
74
75
  end
76
+ ::Protobuf.deprecator.deprecate_methods(method_name)
75
77
  end
76
78
  end
77
79
 
78
80
  end
79
81
  end
80
82
  end
81
-
@@ -23,4 +23,3 @@ module Protobuf
23
23
  end
24
24
  end
25
25
  end
26
-
@@ -9,7 +9,7 @@ module Protobuf
9
9
  #
10
10
 
11
11
  def self.default
12
- raise NoMethodError, "#{self}.#{__method__} must be called on an instance"
12
+ fail NoMethodError, "#{self}.#{__method__} must be called on an instance"
13
13
  end
14
14
 
15
15
  ##
@@ -17,7 +17,7 @@ module Protobuf
17
17
  #
18
18
 
19
19
  def acceptable?(val)
20
- ! type_class.fetch(val).nil?
20
+ !type_class.fetch(val).nil?
21
21
  end
22
22
 
23
23
  def encode(value)
@@ -25,9 +25,7 @@ module Protobuf
25
25
  end
26
26
 
27
27
  def decode(value)
28
- if acceptable?(value)
29
- value
30
- end
28
+ value if acceptable?(value)
31
29
  end
32
30
 
33
31
  def enum?
@@ -49,7 +47,7 @@ module Protobuf
49
47
  @values.delete(field.name)
50
48
  else
51
49
  value = field.type_class.fetch(value)
52
- raise TypeError, "Invalid Enum value: #{orig_value.inspect} for #{field.name}" unless value
50
+ fail TypeError, "Invalid Enum value: #{orig_value.inspect} for #{field.name}" unless value
53
51
 
54
52
  @values[field.name] = value
55
53
  end
@@ -68,4 +66,3 @@ module Protobuf
68
66
  end
69
67
  end
70
68
  end
71
-
@@ -41,7 +41,7 @@ module Protobuf
41
41
  # Return a hash-representation of the given values for this field type.
42
42
  # The value in this case would be an array.
43
43
  def to_hash_value
44
- self.map do |value|
44
+ map do |value|
45
45
  value.respond_to?(:to_hash_value) ? value.to_hash_value : value
46
46
  end
47
47
  end
@@ -62,7 +62,7 @@ module Protobuf
62
62
 
63
63
  def normalize(value)
64
64
  value = value.to_proto if value.respond_to?(:to_proto)
65
- raise TypeError, "Unacceptable value #{value} for field #{field.name} of type #{field.type_class}" unless field.acceptable?(value)
65
+ fail TypeError, "Unacceptable value #{value} for field #{field.name} of type #{field.type_class}" unless field.acceptable?(value)
66
66
 
67
67
  if field.is_a?(::Protobuf::Field::EnumField)
68
68
  field.type_class.fetch(value)
@@ -74,7 +74,7 @@ module Protobuf
74
74
  end
75
75
 
76
76
  def raise_type_error(val)
77
- raise TypeError, <<-TYPE_ERROR
77
+ fail TypeError, <<-TYPE_ERROR
78
78
  Expected repeated value of type '#{field.type_class}'
79
79
  Got '#{val.class}' for repeated protobuf field #{field.name}
80
80
  TYPE_ERROR
@@ -83,4 +83,3 @@ module Protobuf
83
83
  end
84
84
  end
85
85
  end
86
-
@@ -17,7 +17,7 @@ module Protobuf
17
17
  end
18
18
 
19
19
  def wire_type
20
- ::Protobuf::WireType::FIXED32
20
+ ::Protobuf::WireType::FIXED32
21
21
  end
22
22
 
23
23
  end
@@ -26,4 +26,3 @@ module Protobuf
26
26
  end
27
27
  end
28
28
  end
29
-
@@ -39,4 +39,3 @@ module Protobuf
39
39
  end
40
40
  end
41
41
  end
42
-
@@ -19,4 +19,3 @@ module Protobuf
19
19
  end
20
20
  end
21
21
  end
22
-
@@ -19,4 +19,3 @@ module Protobuf
19
19
  end
20
20
  end
21
21
  end
22
-
@@ -21,4 +21,3 @@ module Protobuf
21
21
  end
22
22
  end
23
23
  end
24
-
@@ -10,7 +10,7 @@ module Protobuf
10
10
 
11
11
  def acceptable?(val)
12
12
  unless val.instance_of?(type_class) || val.respond_to?(:to_hash)
13
- raise TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'"
13
+ fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'"
14
14
  end
15
15
 
16
16
  true
@@ -54,7 +54,7 @@ module Protobuf
54
54
  when val.respond_to?(:to_hash) then
55
55
  @values[field.name] = field.type_class.new(val.to_hash)
56
56
  else
57
- raise TypeError, "Expected value of type '#{field.type_class}' for field #{field.name}, but got '#{val.class}'"
57
+ fail TypeError, "Expected value of type '#{field.type_class}' for field #{field.name}, but got '#{val.class}'"
58
58
  end
59
59
  end
60
60
  end
@@ -63,4 +63,3 @@ module Protobuf
63
63
  end
64
64
  end
65
65
  end
66
-
@@ -25,4 +25,3 @@ module Protobuf
25
25
  end
26
26
  end
27
27
  end
28
-
@@ -26,4 +26,3 @@ module Protobuf
26
26
  end
27
27
  end
28
28
  end
29
-
@@ -27,4 +27,3 @@ module Protobuf
27
27
  end
28
28
  end
29
29
  end
30
-
@@ -19,4 +19,3 @@ module Protobuf
19
19
  end
20
20
  end
21
21
  end
22
-
@@ -19,4 +19,3 @@ module Protobuf
19
19
  end
20
20
  end
21
21
  end
22
-
@@ -32,4 +32,3 @@ module Protobuf
32
32
  end
33
33
  end
34
34
  end
35
-
@@ -19,4 +19,3 @@ module Protobuf
19
19
  end
20
20
  end
21
21
  end
22
-
@@ -19,4 +19,3 @@ module Protobuf
19
19
  end
20
20
  end
21
21
  end
22
-
@@ -65,4 +65,3 @@ module Protobuf
65
65
  end
66
66
  end
67
67
  end
68
-
@@ -62,10 +62,9 @@ module Protobuf
62
62
  end
63
63
 
64
64
  def type_namespace
65
- @type_namespace ||= @namespace + [ descriptor.name ]
65
+ @type_namespace ||= @namespace + [descriptor.name]
66
66
  end
67
67
 
68
68
  end
69
69
  end
70
70
  end
71
-
@@ -33,10 +33,9 @@ module Protobuf
33
33
  def build_value(enum_value_descriptor)
34
34
  name = enum_value_descriptor.name
35
35
  number = enum_value_descriptor.number
36
- return "define :#{name}, #{number}"
36
+ "define :#{name}, #{number}"
37
37
  end
38
38
 
39
39
  end
40
40
  end
41
41
  end
42
-
@@ -16,7 +16,7 @@ module Protobuf
16
16
  print_class(@message_type, :message) do
17
17
  group = GroupGenerator.new(current_indent)
18
18
  group.add_extension_fields(@field_descriptors)
19
- group.order = [ :extension_field ]
19
+ group.order = [:extension_field]
20
20
  print group.to_s
21
21
  end
22
22
  end
@@ -25,4 +25,3 @@ module Protobuf
25
25
  end
26
26
  end
27
27
  end
28
-
@@ -54,7 +54,7 @@ module Protobuf
54
54
 
55
55
  def compile
56
56
  run_once(:compile) do
57
- field_definition = [ "#{label} #{type_name}", name, number, applicable_options ]
57
+ field_definition = ["#{label} #{type_name}", name, number, applicable_options]
58
58
  puts field_definition.flatten.compact.join(', ')
59
59
  end
60
60
  end
@@ -91,10 +91,10 @@ module Protobuf
91
91
  @type_name ||= begin
92
92
  case descriptor.type.name
93
93
  when :TYPE_MESSAGE, :TYPE_ENUM, :TYPE_GROUP then
94
- type_name = modulize(descriptor.type_name)
94
+ modulize(descriptor.type_name)
95
95
  else
96
96
  type_name = descriptor.type.name.to_s.downcase.sub(/type_/, '')
97
- type_name = ":#{type_name}"
97
+ ":#{type_name}"
98
98
  end
99
99
  end
100
100
  end
@@ -119,7 +119,7 @@ module Protobuf
119
119
  end
120
120
 
121
121
  def string_default_value
122
- %Q{"#{verbatim_default_value.gsub(/'/, '\\\\\'')}"}
122
+ %("#{verbatim_default_value.gsub(/'/, '\\\\\'')}")
123
123
  end
124
124
 
125
125
  def verbatim_default_value
@@ -129,4 +129,3 @@ module Protobuf
129
129
  end
130
130
  end
131
131
  end
132
-
@@ -22,8 +22,7 @@ module Protobuf
22
22
 
23
23
  def compile
24
24
  run_once(:compile) do
25
- map_extensions(descriptor, [ descriptor.package ])
26
- extract_dangling_extensions
25
+ map_extensions(descriptor, [descriptor.package])
27
26
 
28
27
  print_file_comment
29
28
  print_generic_requires
@@ -31,10 +30,10 @@ module Protobuf
31
30
 
32
31
  print_package do
33
32
  group = GroupGenerator.new(current_indent)
34
- group.add_enums(descriptor.enum_type, :namespace => [ descriptor.package ])
33
+ group.add_enums(descriptor.enum_type, :namespace => [descriptor.package])
35
34
  group.add_message_declarations(descriptor.message_type)
36
- group.add_messages(descriptor.message_type, :extension_fields => @extension_fields, :namespace => [ descriptor.package ])
37
- group.add_extended_messages(@unknown_extensions)
35
+ group.add_messages(descriptor.message_type, :extension_fields => @extension_fields, :namespace => [descriptor.package])
36
+ group.add_extended_messages(unknown_extensions)
38
37
  group.add_services(descriptor.service)
39
38
 
40
39
  group.add_header(:enum, 'Enum Classes')
@@ -48,9 +47,9 @@ module Protobuf
48
47
  end
49
48
  end
50
49
 
51
- def extract_dangling_extensions
52
- @unknown_extensions = @extension_fields.select do |k, v|
53
- ! @known_messages.include?(k)
50
+ def unknown_extensions
51
+ @unknown_extensions ||= @extension_fields.reject do |k, _|
52
+ @known_messages.include?(k)
54
53
  end
55
54
  end
56
55
 
@@ -79,20 +78,18 @@ module Protobuf
79
78
  @extension_fields[field_descriptor.extendee] << field_descriptor
80
79
  end
81
80
 
82
- if descriptor.respond_to_has_and_present?(:message_type)
83
- descriptor.message_type.each do |message_descriptor|
84
- map_extensions(message_descriptor, (namespaces + [ message_descriptor.name ]))
85
- end
86
- end
81
+ [:message_type, :nested_type].each do |type|
82
+ next unless descriptor.respond_to_has_and_present?(type)
87
83
 
88
- if descriptor.respond_to_has_and_present?(:nested_type)
89
- descriptor.nested_type.each do |nested_descriptor|
90
- map_extensions(nested_descriptor, (namespaces + [ nested_descriptor.name ]))
84
+ descriptor.public_send(type).each do |type_descriptor|
85
+ map_extensions(type_descriptor, (namespaces + [type_descriptor.name]))
91
86
  end
92
87
  end
93
88
  end
94
89
 
95
90
  def print_file_comment
91
+ puts "# encoding: utf-8"
92
+ puts
96
93
  puts "##"
97
94
  puts "# This file is auto-generated. DO NOT EDIT!"
98
95
  puts "#"
@@ -105,23 +102,22 @@ module Protobuf
105
102
  end
106
103
 
107
104
  def print_import_requires
108
- if descriptor.dependency.count > 0
109
- header "Imports"
105
+ return if descriptor.dependency.empty?
110
106
 
111
- descriptor.dependency.each do |dependency|
112
- print_require(convert_filename(dependency))
113
- end
107
+ header "Imports"
114
108
 
115
- puts
109
+ descriptor.dependency.each do |dependency|
110
+ print_require(convert_filename(dependency))
116
111
  end
112
+
113
+ puts
117
114
  end
118
115
 
119
116
  def print_package(&block)
120
- final = lambda { block.call }
121
117
  namespaces = descriptor.package.split('.')
122
- namespaces.reverse.inject(final) { |previous, namespace|
123
- lambda { print_module(namespace, &previous) }
124
- }.call
118
+ namespaces.reverse.reduce(block) do |previous, namespace|
119
+ -> { print_module(namespace, &previous) }
120
+ end.call
125
121
  end
126
122
 
127
123
  private
@@ -137,4 +133,3 @@ module Protobuf
137
133
  end
138
134
  end
139
135
  end
140
-
@@ -18,7 +18,7 @@ module Protobuf
18
18
  @comments = {}
19
19
  @handlers = {}
20
20
  @indent_level = indent_level
21
- @order = [ :enum, :message_declaration, :message, :extended_message, :service ]
21
+ @order = [:enum, :message_declaration, :message, :extended_message, :service]
22
22
  init_printer(indent_level)
23
23
  end
24
24
 
@@ -80,25 +80,25 @@ module Protobuf
80
80
  def compile
81
81
  @order.each do |type|
82
82
  items = @groups[type]
83
- if items.count > 0
84
- item_handler = @handlers[type]
83
+ next if items.empty?
85
84
 
86
- item_header = @headers[type]
87
- header(item_header) if item_header
85
+ item_handler = @handlers[type]
88
86
 
89
- item_comment = @comments[type]
90
- comment(item_comment) if item_comment
87
+ item_header = @headers[type]
88
+ header(item_header) if item_header
91
89
 
92
- items.each do |item|
93
- if item_handler
94
- puts item_handler.call(item)
95
- else
96
- print item.to_s
97
- end
98
- end
90
+ item_comment = @comments[type]
91
+ comment(item_comment) if item_comment
99
92
 
100
- puts if type == :message_declaration
93
+ items.each do |item|
94
+ if item_handler
95
+ puts item_handler.call(item)
96
+ else
97
+ print item.to_s
98
+ end
101
99
  end
100
+
101
+ puts if type == :message_declaration
102
102
  end
103
103
  end
104
104
 
@@ -110,4 +110,3 @@ module Protobuf
110
110
  end
111
111
  end
112
112
  end
113
-