protobuf 3.7.0.pre0 → 3.7.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49fd33e80978059efd20c7e085db8567e84b3bf4
4
- data.tar.gz: c56d562e6ba4814d8b023a9761b14d5eef3d719f
3
+ metadata.gz: 2572788305cda35ff4cc6fde499167d9658d080b
4
+ data.tar.gz: 941f6a8239dbc36d8bc3e299dd07f37986c0bc11
5
5
  SHA512:
6
- metadata.gz: 56a1dfac3b2e3db4eb26115ecae1ced9585797651551df00b13eabbb2ecaafa8e61ef7ee3e396f1ea9df1377e1c4180983fe79e698e7bcb402042307fed05dc8
7
- data.tar.gz: a4cca36a18e7f24e2ed319323bbf0c41c61730d23555d3b52965b93eaf6baea0336af4beb66fe96422f78204d547684b642b74e4dd725e04e4c48b2825e756c9
6
+ metadata.gz: bc704397840f6e029fdc8b7a7cff5cc659ab077998e0f688f1babcbd55473155bf626e953ef7d88fdf17192b38d26256d571284c0c7e028e047b4c59131b138f
7
+ data.tar.gz: 684348b64a203f308076e1c41f6c76d4442cf7d5edd529a68016139f1cec83a98e37a71c854254fa8edef41a9cf536672708bb8cfb3e0acc4f99ceff108a66d2
@@ -1,5 +1,8 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
+ AllCops:
4
+ DisplayCopNames: true
5
+
3
6
  Lint/EndAlignment:
4
7
  AlignWith: keyword
5
8
 
@@ -46,6 +49,9 @@ Style/IndentHash:
46
49
  Style/Semicolon:
47
50
  AllowAsExpressionSeparator: true
48
51
 
52
+ Style/SingleLineBlockParams:
53
+ Enabled: false
54
+
49
55
  Style/TrailingBlankLines:
50
56
  Exclude:
51
57
  - '**/*.pb.rb'
data/CHANGES.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Stable (3.x)
2
2
 
3
+ 3.7.0 (pre1)
4
+ -----------
5
+ - BUG: Revert to old behavior for setting repeated fields to nil
6
+ - BUG: Set binmode for protoc-gen-ruby STDIN and STDOUT to compile proto files on Windows
7
+ - Make all things Optionable and fix requires
8
+
3
9
  3.7.0 (pre0)
4
10
  -----------
5
11
  - Add `PB_USE_RAW_RPC_NAMES` option to preserve raw RPC name (since #underscore can be lossy).
@@ -10,6 +10,12 @@ require 'protobuf'
10
10
  require 'protobuf/descriptors'
11
11
  require 'protobuf/code_generator'
12
12
 
13
+ # Ensure that no encoding conversions are done on STDIN and STDOUT since
14
+ # we are passing binary data back and forth. Otherwise these streams
15
+ # will be mangled on Windows.
16
+ STDIN.binmode
17
+ STDOUT.binmode
18
+
13
19
  request_bytes = STDIN.read
14
20
  code_generator = ::Protobuf::CodeGenerator.new(request_bytes)
15
21
  response_bytes = code_generator.response_bytes
@@ -9,7 +9,24 @@ require 'active_support/inflector'
9
9
  require 'active_support/json'
10
10
  require 'active_support/notifications'
11
11
 
12
+ # All top-level run time code requires, ordered by necessity
13
+ require 'protobuf/wire_type'
14
+
15
+ require 'protobuf/varint_pure'
16
+ require 'protobuf/varint'
17
+
18
+ require 'protobuf/exceptions'
12
19
  require 'protobuf/deprecation'
20
+ require 'protobuf/logging'
21
+
22
+ require 'protobuf/encoder'
23
+ require 'protobuf/decoder'
24
+
25
+ require 'protobuf/optionable'
26
+ require 'protobuf/field'
27
+ require 'protobuf/enum'
28
+ require 'protobuf/message'
29
+ require 'protobuf/descriptors'
13
30
 
14
31
  module Protobuf
15
32
 
@@ -1,6 +1,3 @@
1
- require 'protobuf/wire_type'
2
- require 'protobuf/exceptions'
3
-
4
1
  module Protobuf
5
2
  class Decoder
6
3
 
@@ -1,6 +1,4 @@
1
1
  require 'delegate'
2
- require 'protobuf/deprecation'
3
- require 'protobuf/optionable'
4
2
 
5
3
  ##
6
4
  # Adding extension to Numeric until
@@ -12,7 +10,7 @@ require 'protobuf/optionable'
12
10
  module Protobuf
13
11
  class Enum < SimpleDelegator
14
12
  # Public: Allows setting Options on the Enum class.
15
- include ::Protobuf::Optionable
13
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::EnumOptions }
16
14
 
17
15
  def self.aliases_allowed?
18
16
  get_option(:allow_alias)
@@ -1,12 +1,9 @@
1
- require 'protobuf/deprecation'
2
1
  require 'protobuf/field/field_array'
3
- require 'protobuf/logging'
4
- require 'protobuf/wire_type'
5
-
6
2
  module Protobuf
7
3
  module Field
8
4
  class BaseField
9
5
  include ::Protobuf::Logging
6
+ ::Protobuf::Optionable.inject(self, false) { ::Google::Protobuf::FieldOptions }
10
7
 
11
8
  ##
12
9
  # Constants
@@ -185,7 +182,7 @@ module Protobuf
185
182
 
186
183
  message_class.class_eval do
187
184
  define_method(simple_field_name) { self[fully_qualified_field_name] }
188
- define_method("#{simple_field_name}=") { |v| self[fully_qualified_field_name] = v }
185
+ define_method("#{simple_field_name}=") { |v| set_field(fully_qualified_field_name, v, false) }
189
186
  end
190
187
 
191
188
  return unless deprecated?
@@ -29,6 +29,7 @@ module Protobuf
29
29
  print_import_requires
30
30
 
31
31
  print_package do
32
+ inject_optionable
32
33
  group = GroupGenerator.new(current_indent)
33
34
  group.add_enums(descriptor.enum_type, :namespace => [descriptor.package])
34
35
  group.add_message_declarations(descriptor.message_type)
@@ -104,7 +105,7 @@ module Protobuf
104
105
  end
105
106
 
106
107
  def print_generic_requires
107
- print_require("protobuf/message")
108
+ print_require("protobuf")
108
109
  print_require("protobuf/rpc/service") if descriptor.service.count > 0
109
110
  puts
110
111
  end
@@ -123,6 +124,9 @@ module Protobuf
123
124
 
124
125
  def print_package(&block)
125
126
  namespaces = descriptor.package.split('.')
127
+ if namespaces.empty? && ENV.key?('PB_ALLOW_DEFAULT_PACKAGE_NAME')
128
+ namespaces = [File.basename(descriptor.name).sub('.proto', '')]
129
+ end
126
130
  namespaces.reverse.reduce(block) do |previous, namespace|
127
131
  -> { print_module(namespace, &previous) }
128
132
  end.call
@@ -138,6 +142,10 @@ module Protobuf
138
142
  token[0] == '.'
139
143
  end
140
144
 
145
+ def inject_optionable
146
+ return if descriptor.package.empty? && !ENV.key?('PB_ALLOW_DEFAULT_PACKAGE_NAME')
147
+ puts "::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }"
148
+ end
141
149
  end
142
150
  end
143
151
  end
@@ -1,7 +1,3 @@
1
- require 'protobuf/field'
2
- require 'protobuf/deprecation'
3
- require 'protobuf/enum'
4
- require 'protobuf/exceptions'
5
1
  require 'protobuf/message/fields'
6
2
  require 'protobuf/message/serialization'
7
3
 
@@ -25,6 +21,7 @@ module Protobuf
25
21
 
26
22
  extend ::Protobuf::Message::Fields
27
23
  include ::Protobuf::Message::Serialization
24
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::MessageOptions }
28
25
 
29
26
  ##
30
27
  # Class Methods
@@ -41,7 +38,7 @@ module Protobuf
41
38
  def initialize(fields = {})
42
39
  @values = {}
43
40
  fields.to_hash.each do |name, value|
44
- self[name] = value
41
+ set_field(name, value, true)
45
42
  end
46
43
 
47
44
  yield self if block_given?
@@ -163,8 +160,37 @@ module Protobuf
163
160
  end
164
161
 
165
162
  def []=(name, value)
163
+ set_field(name, value, true)
164
+ end
165
+
166
+ ##
167
+ # Instance Aliases
168
+ #
169
+ alias_method :to_hash_value, :to_hash
170
+ alias_method :to_proto_hash, :to_hash
171
+ alias_method :responds_to_has?, :respond_to_has?
172
+ alias_method :respond_to_and_has?, :respond_to_has?
173
+ alias_method :responds_to_and_has?, :respond_to_has?
174
+ alias_method :respond_to_has_present?, :respond_to_has_and_present?
175
+ alias_method :respond_to_and_has_present?, :respond_to_has_and_present?
176
+ alias_method :respond_to_and_has_and_present?, :respond_to_has_and_present?
177
+ alias_method :responds_to_has_present?, :respond_to_has_and_present?
178
+ alias_method :responds_to_and_has_present?, :respond_to_has_and_present?
179
+ alias_method :responds_to_and_has_and_present?, :respond_to_has_and_present?
180
+
181
+ ##
182
+ # Private Instance Methods
183
+ #
184
+
185
+ private
186
+
187
+ def set_field(name, value, ignore_nil_for_repeated)
166
188
  if (field = self.class.get_field(name, true))
167
189
  if field.repeated?
190
+ if value.nil? && ignore_nil_for_repeated
191
+ ::Protobuf.deprecator.deprecation_warning("#{self.class}#[#{name}]=nil", "use an empty array instead of nil")
192
+ return
193
+ end
168
194
  if value.is_a?(Array)
169
195
  value = value.compact
170
196
  else
@@ -196,27 +222,6 @@ module Protobuf
196
222
  end
197
223
  end
198
224
 
199
- ##
200
- # Instance Aliases
201
- #
202
- alias_method :to_hash_value, :to_hash
203
- alias_method :to_proto_hash, :to_hash
204
- alias_method :responds_to_has?, :respond_to_has?
205
- alias_method :respond_to_and_has?, :respond_to_has?
206
- alias_method :responds_to_and_has?, :respond_to_has?
207
- alias_method :respond_to_has_present?, :respond_to_has_and_present?
208
- alias_method :respond_to_and_has_present?, :respond_to_has_and_present?
209
- alias_method :respond_to_and_has_and_present?, :respond_to_has_and_present?
210
- alias_method :responds_to_has_present?, :respond_to_has_and_present?
211
- alias_method :responds_to_and_has_present?, :respond_to_has_and_present?
212
- alias_method :responds_to_and_has_and_present?, :respond_to_has_and_present?
213
-
214
- ##
215
- # Private Instance Methods
216
- #
217
-
218
- private
219
-
220
225
  def copy_to(object, method)
221
226
  duplicate = proc do |obj|
222
227
  case obj
@@ -1,17 +1,36 @@
1
- require 'active_support/concern'
2
-
3
1
  module Protobuf
4
2
  module Optionable
5
- extend ::ActiveSupport::Concern
6
-
7
3
  module ClassMethods
8
4
  def get_option(name)
9
- @_optionable_options.try(:[], name)
5
+ name = name.to_s
6
+ option = optionable_descriptor_class.get_field(name, true)
7
+ fail ArgumentError, "invalid option=#{name}" unless option
8
+ unless option.fully_qualified_name.to_s == name
9
+ # Eventually we'll deprecate the use of simple names of fields completely, but for now make sure people
10
+ # are accessing options correctly. We allow simple names in other places for backwards compatibility.
11
+ fail ArgumentError, "must access option using its fully qualified name: #{option.fully_qualified_name.inspect}"
12
+ end
13
+ if @_optionable_options.try(:key?, name)
14
+ value = @_optionable_options[name]
15
+ else
16
+ value = option.default_value
17
+ end
18
+ if option.type_class < ::Protobuf::Message
19
+ option.type_class.new(value)
20
+ else
21
+ value
22
+ end
23
+ end
24
+
25
+ def get_option!(name)
26
+ get_option(name) if @_optionable_options.try(:key?, name.to_s)
10
27
  end
11
28
 
29
+ private
30
+
12
31
  def set_option(name, value = true)
13
32
  @_optionable_options ||= {}
14
- @_optionable_options[name] = value
33
+ @_optionable_options[name.to_s] = value
15
34
  end
16
35
  end
17
36
 
@@ -19,5 +38,33 @@ module Protobuf
19
38
  self.class.get_option(name)
20
39
  end
21
40
 
41
+ def get_option!(name)
42
+ self.class.get_option!(name)
43
+ end
44
+
45
+ def self.inject(base_class, extend_class = true, &block)
46
+ unless block_given?
47
+ fail ArgumentError, 'missing option class block (e.g: ::Google::Protobuf::MessageOptions)'
48
+ end
49
+ if extend_class
50
+ # Check if optionable_descriptor_class is already defined and short circuit if so.
51
+ # File options are injected per module, and since a module can be defined more than once,
52
+ # we will get a warning if we try to define optionable_descriptor_class twice.
53
+ if base_class.respond_to?(:optionable_descriptor_class)
54
+ if base_class.optionable_descriptor_class != block.call
55
+ fail 'A class is being defined with two different descriptor classes, something is very wrong'
56
+ else
57
+ return # Don't define optionable_descriptor_class twice
58
+ end
59
+ end
60
+
61
+ base_class.extend(ClassMethods)
62
+ base_class.__send__(:include, self)
63
+ base_class.define_singleton_method(:optionable_descriptor_class, block)
64
+ else
65
+ base_class.__send__(:include, ClassMethods)
66
+ base_class.module_eval { define_method(:optionable_descriptor_class, block) }
67
+ end
68
+ end
22
69
  end
23
70
  end
@@ -1,6 +1,5 @@
1
- require 'active_support/core_ext/class'
2
-
3
1
  require 'protobuf/logging'
2
+ require 'protobuf/message'
4
3
  require 'protobuf/rpc/client'
5
4
  require 'protobuf/rpc/error'
6
5
  require 'protobuf/rpc/service_filters'
@@ -14,6 +13,7 @@ module Protobuf
14
13
  class Service
15
14
  include ::Protobuf::Logging
16
15
  include ::Protobuf::Rpc::ServiceFilters
16
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::ServiceOptions }
17
17
 
18
18
  DEFAULT_HOST = '127.0.0.1'.freeze
19
19
  DEFAULT_PORT = 9399
@@ -1,5 +1,3 @@
1
- require 'protobuf/varint_pure'
2
-
3
1
  module Protobuf
4
2
  class Varint
5
3
  if defined?(::Varint)
@@ -1,3 +1,3 @@
1
1
  module Protobuf
2
- VERSION = '3.7.0.pre0'
2
+ VERSION = '3.7.0.pre1'
3
3
  end
@@ -27,7 +27,8 @@ require "protobuf/version"
27
27
  s.add_development_dependency 'ffi-rzmq'
28
28
  s.add_development_dependency 'rake'
29
29
  s.add_development_dependency 'rspec', '>= 3.0'
30
- s.add_development_dependency 'rubocop', '0.34.2'
30
+ s.add_development_dependency "rubocop", "~> 0.35.0"
31
+ s.add_development_dependency "parser", "2.3.0.6" # Locked this down since 2.3.0.7 causes issues. https://github.com/bbatsov/rubocop/pull/2984
31
32
  s.add_development_dependency 'simplecov'
32
33
  s.add_development_dependency 'timecop'
33
34
  s.add_development_dependency 'yard'
@@ -22,8 +22,8 @@ RSpec.describe Protobuf::Enum do
22
22
  end
23
23
 
24
24
  describe '.aliases_allowed?' do
25
- it 'is nil when the option is not set' do
26
- expect(Test::EnumTestType.aliases_allowed?).to be nil
25
+ it 'is false when the option is not set' do
26
+ expect(Test::EnumTestType.aliases_allowed?).to be false
27
27
  end
28
28
  end
29
29
 
@@ -57,7 +57,7 @@ RSpec.describe Protobuf::Enum do
57
57
  Test::EnumTestType::TWO,
58
58
  Test::EnumTestType::MINUS_ONE,
59
59
  Test::EnumTestType::THREE,
60
- ],
60
+ ]
61
61
  )
62
62
  end
63
63
 
@@ -68,7 +68,7 @@ RSpec.describe Protobuf::Enum do
68
68
  EnumAliasTest::FOO,
69
69
  EnumAliasTest::BAR,
70
70
  EnumAliasTest::BAZ,
71
- ],
71
+ ]
72
72
  )
73
73
  end
74
74
  end
@@ -29,4 +29,37 @@ RSpec.describe ::Protobuf::Generators::FileGenerator do
29
29
 
30
30
  end
31
31
 
32
+ describe '#compile' do
33
+ it 'generates the file contents' do
34
+ subject.compile
35
+ expect(subject.to_s).to eq <<EOF
36
+ # encoding: utf-8
37
+
38
+ ##
39
+ # This file is auto-generated. DO NOT EDIT!
40
+ #
41
+ require 'protobuf'
42
+
43
+ EOF
44
+ end
45
+
46
+ it 'generates the file contents using default package name' do
47
+ allow(ENV).to receive(:key?).with('PB_ALLOW_DEFAULT_PACKAGE_NAME')
48
+ .and_return(true)
49
+ subject.compile
50
+ expect(subject.to_s).to eq <<EOF
51
+ # encoding: utf-8
52
+
53
+ ##
54
+ # This file is auto-generated. DO NOT EDIT!
55
+ #
56
+ require 'protobuf'
57
+
58
+ module Foo
59
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
60
+ end
61
+
62
+ EOF
63
+ end
64
+ end
32
65
  end
@@ -181,6 +181,12 @@ RSpec.describe Protobuf::Message do
181
181
  test_enum = Test::EnumTestMessage.new { |p| p.non_default_enum = 2 }
182
182
  expect(test_enum.non_default_enum).to eq(2)
183
183
  end
184
+
185
+ # to be deprecated
186
+ it "allows you to pass nil to repeated fields" do
187
+ test = Test::Resource.new(:repeated_enum => nil)
188
+ expect(test.repeated_enum).to eq([])
189
+ end
184
190
  end
185
191
 
186
192
  describe '#encode' do
@@ -444,6 +450,10 @@ RSpec.describe Protobuf::Message do
444
450
  expect { subject.name = 1 }.to raise_error(/name/)
445
451
  end
446
452
 
453
+ it 'does not allow a repeated field is set to nil' do
454
+ expect { subject.repeated_enum = nil }.to raise_error(TypeError)
455
+ end
456
+
447
457
  context '#{simple_field_name}!' do
448
458
  it 'returns value of set field' do
449
459
  expect(::Test::Resource.new(:name => "Joe").name!).to eq("Joe")
@@ -723,6 +733,17 @@ RSpec.describe Protobuf::Message do
723
733
  instance[100] = true
724
734
  expect(instance[:ext_is_searchable]).to eq(true)
725
735
  end
736
+
737
+ # to be deprecated
738
+ it 'does nothing when sent an empty array' do
739
+ instance[:repeated_enum] = nil
740
+ expect(instance[:repeated_enum]).to eq([])
741
+ instance[:repeated_enum] = [1, 2]
742
+ expect(instance[:repeated_enum]).to eq([1, 2])
743
+ instance[:repeated_enum] = nil
744
+ # Yes this is very silly, but backwards compatible
745
+ expect(instance[:repeated_enum]).to eq([1, 2])
746
+ end
726
747
  end
727
748
 
728
749
  context 'throwing TypeError' do
@@ -1,46 +1,169 @@
1
1
  require 'spec_helper'
2
2
  require 'protobuf/optionable'
3
+ require 'protobuf/field/message_field'
3
4
 
4
5
  RSpec.describe 'Optionable' do
6
+ describe '.{get,get!}_option' do
7
+ before do
8
+ stub_const("OptionableGetOptionTest", Class.new(::Protobuf::Message) do
9
+ set_option :deprecated, true
10
+ set_option :".package.message_field", :field => 33
5
11
 
6
- describe '.set_option' do
7
- before(:all) do
8
- OptionableSetOptionTest = ::Class.new do
9
- include ::Protobuf::Optionable
10
- end
12
+ optional :int32, :field, 1
13
+ end)
14
+ end
15
+
16
+ it '.get_option retrieves the option as a symbol' do
17
+ expect(OptionableGetOptionTest.get_option(:deprecated)).to be(true)
18
+ end
19
+
20
+ it '.get_option returns the default value for unset options' do
21
+ expect(OptionableGetOptionTest.get_option(:message_set_wire_format)).to be(false)
22
+ end
23
+
24
+ it '.get_option retrieves the option as a string' do
25
+ expect(OptionableGetOptionTest.get_option('deprecated')).to be(true)
26
+ end
27
+
28
+ it '.get_option errors if the option does not exist' do
29
+ expect { OptionableGetOptionTest.get_option(:baz) }.to raise_error(ArgumentError)
30
+ end
31
+
32
+ it '.get_option errors if the option is not accessed by its fully qualified name' do
33
+ message_field = ::Protobuf::Field::MessageField.new(
34
+ OptionableGetOptionTest, :optional, OptionableGetOptionTest, '.package.message_field', 2, '.message_field', {})
35
+ allow(::Google::Protobuf::MessageOptions).to receive(:get_field).and_return(message_field)
36
+ expect { OptionableGetOptionTest.get_option(message_field.name) }.to raise_error(ArgumentError)
37
+ end
38
+
39
+ it '.get_option can return an option representing a message' do
40
+ message_field = ::Protobuf::Field::MessageField.new(
41
+ OptionableGetOptionTest, :optional, OptionableGetOptionTest, '.package.message_field', 2, 'message_field', {})
42
+ allow(::Google::Protobuf::MessageOptions).to receive(:get_field).and_return(message_field)
43
+ expect(OptionableGetOptionTest.get_option(message_field.fully_qualified_name)).to eq(OptionableGetOptionTest.new(:field => 33))
44
+ end
45
+
46
+ it '.get_option! retrieves explicitly an set option' do
47
+ expect(OptionableGetOptionTest.get_option!(:deprecated)).to be(true)
48
+ end
49
+
50
+ it '.get_option! returns nil for unset options' do
51
+ expect(OptionableGetOptionTest.get_option!(:message_set_wire_format)).to be(nil)
52
+ end
53
+
54
+ it '.get_option! errors if the option does not exist' do
55
+ expect { OptionableGetOptionTest.get_option(:baz) }.to raise_error(ArgumentError)
56
+ end
57
+
58
+ it '#get_option retrieves the option as a symbol' do
59
+ expect(OptionableGetOptionTest.new.get_option(:deprecated)).to be(true)
60
+ end
61
+
62
+ it '#get_option returns the default value for unset options' do
63
+ expect(OptionableGetOptionTest.new.get_option(:message_set_wire_format)).to be(false)
11
64
  end
12
65
 
13
- it 'stores the given option and value' do
14
- expect(OptionableSetOptionTest).to respond_to(:set_option)
15
- expect(OptionableSetOptionTest.method(:set_option).arity).to eq(-2)
16
- expect do
17
- OptionableSetOptionTest.set_option(:foo, :bar)
18
- end.to_not raise_error
66
+ it '#get_option retrieves the option as a string' do
67
+ expect(OptionableGetOptionTest.new.get_option('deprecated')).to be(true)
19
68
  end
20
69
 
21
- it 'defaults the value to true' do
22
- OptionableSetOptionTest.set_option(:baz_enabled)
23
- expect(OptionableSetOptionTest.get_option(:baz_enabled)).to be true
70
+ it '#get_option errors if the option is not accessed by its fully qualified name' do
71
+ message_field = ::Protobuf::Field::MessageField.new(
72
+ OptionableGetOptionTest, :optional, OptionableGetOptionTest, '.package.message_field', 2, 'message_field', {})
73
+ allow(::Google::Protobuf::MessageOptions).to receive(:get_field).and_return(message_field)
74
+ expect { OptionableGetOptionTest.new.get_option(message_field.name) }.to raise_error(ArgumentError)
75
+ end
76
+
77
+ it '#get_option can return an option representing a message' do
78
+ message_field = ::Protobuf::Field::MessageField.new(
79
+ OptionableGetOptionTest, :optional, OptionableGetOptionTest, '.package.message_field', 2, 'message_field', {})
80
+ allow(::Google::Protobuf::MessageOptions).to receive(:get_field).and_return(message_field)
81
+ expect(OptionableGetOptionTest.new.get_option(message_field.fully_qualified_name)).to eq(OptionableGetOptionTest.new(:field => 33))
82
+ end
83
+
84
+ it '#get_option errors if the option does not exist' do
85
+ expect { OptionableGetOptionTest.new.get_option(:baz) }.to raise_error(ArgumentError)
86
+ end
87
+
88
+ it '#get_option! retrieves explicitly an set option' do
89
+ expect(OptionableGetOptionTest.new.get_option!(:deprecated)).to be(true)
90
+ end
91
+
92
+ it '#get_option! returns nil for unset options' do
93
+ expect(OptionableGetOptionTest.new.get_option!(:message_set_wire_format)).to be(nil)
94
+ end
95
+
96
+ it '#get_option! errors if the option does not exist' do
97
+ expect { OptionableGetOptionTest.new.get_option(:baz) }.to raise_error(ArgumentError)
24
98
  end
25
99
  end
26
100
 
27
- describe '.get_option' do
28
- before(:all) do
29
- OptionableGetOptionTest = ::Class.new do
30
- include ::Protobuf::Optionable
31
- set_option :foo, :bar
101
+ describe '.inject' do
102
+ let(:klass) { Class.new }
103
+
104
+ it 'adds klass.{set,get}_option' do
105
+ expect { klass.get_option(:deprecated) }.to raise_error(NoMethodError)
106
+ expect { klass.__send__(:set_option, :deprecated, true) }.to raise_error(NoMethodError)
107
+ ::Protobuf::Optionable.inject(klass) { ::Google::Protobuf::MessageOptions }
108
+ expect(klass.get_option(:deprecated)).to eq(false)
109
+ expect { klass.set_option(:deprecated, true) }.to raise_error(NoMethodError)
110
+ klass.__send__(:set_option, :deprecated, true)
111
+ expect(klass.get_option(:deprecated)).to eq(true)
112
+ end
113
+
114
+ it 'adds klass#get_option' do
115
+ expect { klass.new.get_option(:deprecated) }.to raise_error(NoMethodError)
116
+ ::Protobuf::Optionable.inject(klass) { ::Google::Protobuf::MessageOptions }
117
+ expect(klass.new.get_option(:deprecated)).to eq(false)
118
+ end
119
+
120
+ it 'adds klass.optionable_descriptor_class' do
121
+ expect { klass.optionable_descriptor_class }.to raise_error(NoMethodError)
122
+ ::Protobuf::Optionable.inject(klass) { ::Google::Protobuf::MessageOptions }
123
+ expect(klass.optionable_descriptor_class).to eq(::Google::Protobuf::MessageOptions)
124
+ end
125
+
126
+ it 'does not add klass.optionable_descriptor_class twice' do
127
+ expect(klass).to receive(:define_singleton_method).once
128
+ ::Protobuf::Optionable.inject(klass) { ::Google::Protobuf::MessageOptions }
129
+ klass.instance_eval do
130
+ def optionable_descriptor_class
131
+ ::Google::Protobuf::MessageOptions
132
+ end
32
133
  end
134
+ ::Protobuf::Optionable.inject(klass) { ::Google::Protobuf::MessageOptions }
33
135
  end
34
136
 
35
- it 'retrieves the option for the given name, if any' do
36
- expect(OptionableGetOptionTest.get_option(:foo)).to eq(:bar)
37
- expect(OptionableGetOptionTest.get_option(:baz)).to be_nil
137
+ it 'throws error when klass.optionable_descriptor_class defined twice with different args' do
138
+ ::Protobuf::Optionable.inject(klass) { ::Google::Protobuf::MessageOptions }
139
+ expect { ::Protobuf::Optionable.inject(klass) { ::Google::Protobuf::FileOptions } }
140
+ .to raise_error('A class is being defined with two different descriptor classes, something is very wrong')
38
141
  end
39
142
 
40
- it 'retrieves the option in the context of an instance' do
41
- expect(OptionableGetOptionTest.new.get_option(:foo)).to eq(:bar)
42
- expect(OptionableGetOptionTest.new.get_option(:baz)).to be_nil
143
+ context 'extend_class = false' do
144
+ let(:object) { klass.new }
145
+ it 'adds object.{get,set}_option' do
146
+ expect { object.get_option(:deprecated) }.to raise_error(NoMethodError)
147
+ expect { object.__send__(:set_option, :deprecated, true) }.to raise_error(NoMethodError)
148
+ ::Protobuf::Optionable.inject(klass, false) { ::Google::Protobuf::MessageOptions }
149
+ expect(object.get_option(:deprecated)).to eq(false)
150
+ expect { object.set_option(:deprecated, true) }.to raise_error(NoMethodError)
151
+ object.__send__(:set_option, :deprecated, true)
152
+ expect(object.get_option(:deprecated)).to eq(true)
153
+ end
154
+
155
+ it 'does not add klass.{get,set}_option' do
156
+ expect { object.get_option(:deprecated) }.to raise_error(NoMethodError)
157
+ ::Protobuf::Optionable.inject(klass, false) { ::Google::Protobuf::MessageOptions }
158
+ expect { klass.get_option(:deprecated) }.to raise_error(NoMethodError)
159
+ expect { klass.__send__(:set_option, :deprecated) }.to raise_error(NoMethodError)
160
+ end
161
+
162
+ it 'creates an instance method optionable_descriptor_class' do
163
+ expect { object.optionable_descriptor_class }.to raise_error(NoMethodError)
164
+ ::Protobuf::Optionable.inject(klass, false) { ::Google::Protobuf::MessageOptions }
165
+ expect(object.optionable_descriptor_class).to eq(::Google::Protobuf::MessageOptions)
166
+ end
43
167
  end
44
168
  end
45
-
46
169
  end
@@ -362,7 +362,7 @@ RSpec.describe Protobuf::Rpc::ServiceFilters do
362
362
  :endpoint,
363
363
  :inner_around_bottom,
364
364
  :outer_around_bottom,
365
- ],
365
+ ]
366
366
  )
367
367
  end
368
368
 
@@ -390,7 +390,7 @@ RSpec.describe Protobuf::Rpc::ServiceFilters do
390
390
  :outer_around_top,
391
391
  :inner_around,
392
392
  :outer_around_bottom,
393
- ],
393
+ ]
394
394
  )
395
395
  end
396
396
 
@@ -3,7 +3,7 @@
3
3
  ##
4
4
  # This file is auto-generated. DO NOT EDIT!
5
5
  #
6
- require 'protobuf/message'
6
+ require 'protobuf'
7
7
 
8
8
 
9
9
  ##
@@ -12,6 +12,7 @@ require 'protobuf/message'
12
12
  require 'protos/resource.pb'
13
13
 
14
14
  module Test
15
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
15
16
 
16
17
  ##
17
18
  # Enum Classes
@@ -3,7 +3,7 @@
3
3
  ##
4
4
  # This file is auto-generated. DO NOT EDIT!
5
5
  #
6
- require 'protobuf/message'
6
+ require 'protobuf'
7
7
  require 'protobuf/rpc/service'
8
8
 
9
9
 
@@ -13,6 +13,7 @@ require 'protobuf/rpc/service'
13
13
  require 'protos/google_unittest_import.pb'
14
14
 
15
15
  module Protobuf_unittest
16
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
16
17
 
17
18
  ##
18
19
  # Enum Classes
@@ -3,7 +3,7 @@
3
3
  ##
4
4
  # This file is auto-generated. DO NOT EDIT!
5
5
  #
6
- require 'protobuf/message'
6
+ require 'protobuf'
7
7
 
8
8
 
9
9
  ##
@@ -12,6 +12,7 @@ require 'protobuf/message'
12
12
  require 'protos/google_unittest_import_public.pb'
13
13
 
14
14
  module Protobuf_unittest_import
15
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
15
16
 
16
17
  ##
17
18
  # Enum Classes
@@ -3,9 +3,10 @@
3
3
  ##
4
4
  # This file is auto-generated. DO NOT EDIT!
5
5
  #
6
- require 'protobuf/message'
6
+ require 'protobuf'
7
7
 
8
8
  module Protobuf_unittest_import
9
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
9
10
 
10
11
  ##
11
12
  # Message Classes
@@ -3,9 +3,10 @@
3
3
  ##
4
4
  # This file is auto-generated. DO NOT EDIT!
5
5
  #
6
- require 'protobuf/message'
6
+ require 'protobuf'
7
7
 
8
8
  module Test
9
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
9
10
 
10
11
  ##
11
12
  # Message Classes
@@ -3,10 +3,11 @@
3
3
  ##
4
4
  # This file is auto-generated. DO NOT EDIT!
5
5
  #
6
- require 'protobuf/message'
6
+ require 'protobuf'
7
7
  require 'protobuf/rpc/service'
8
8
 
9
9
  module Test
10
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
10
11
 
11
12
  ##
12
13
  # Enum Classes
@@ -31,7 +31,7 @@ class StubServer
31
31
  :worker_port => 9400,
32
32
  :delay => 0,
33
33
  :server => Protobuf::Rpc::Socket::Server,
34
- ),
34
+ )
35
35
  )
36
36
 
37
37
  start
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0.pre0
4
+ version: 3.7.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - BJ Neilsen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-03-28 00:00:00.000000000 Z
14
+ date: 2016-05-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -113,18 +113,32 @@ dependencies:
113
113
  version: '3.0'
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: rubocop
116
+ requirement: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - "~>"
119
+ - !ruby/object:Gem::Version
120
+ version: 0.35.0
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: 0.35.0
128
+ - !ruby/object:Gem::Dependency
129
+ name: parser
116
130
  requirement: !ruby/object:Gem::Requirement
117
131
  requirements:
118
132
  - - '='
119
133
  - !ruby/object:Gem::Version
120
- version: 0.34.2
134
+ version: 2.3.0.6
121
135
  type: :development
122
136
  prerelease: false
123
137
  version_requirements: !ruby/object:Gem::Requirement
124
138
  requirements:
125
139
  - - '='
126
140
  - !ruby/object:Gem::Version
127
- version: 0.34.2
141
+ version: 2.3.0.6
128
142
  - !ruby/object:Gem::Dependency
129
143
  name: simplecov
130
144
  requirement: !ruby/object:Gem::Requirement
@@ -437,7 +451,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
437
451
  version: 1.3.1
438
452
  requirements: []
439
453
  rubyforge_project:
440
- rubygems_version: 2.5.1
454
+ rubygems_version: 2.4.5
441
455
  signing_key:
442
456
  specification_version: 4
443
457
  summary: Google Protocol Buffers serialization and RPC implementation for Ruby.