protobuf 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/protobuf.rb +13 -0
- data/lib/protobuf/message.rb +6 -2
- data/lib/protobuf/version.rb +1 -1
- data/spec/lib/protobuf/message_spec.rb +49 -0
- data/spec/lib/protobuf_spec.rb +20 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e5a341fcb307dfd13d03e56530493f316dadff4
|
4
|
+
data.tar.gz: 1dde8b64fe387bd0bcd87e5823e02bec8322bf25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5511c46d74eb0e669400ab394fef865e4e1a8c0a919a967a1d1b97fba19e0dcb8073c08155b9a4fada0043bafb803adaad1d3019f3f293e367c41d9873ba6c10
|
7
|
+
data.tar.gz: 9c5f985a0ab726096f1bb662e48b2a9fe78133a5d523421ccdb93b43aad6aabc1fd45cce0e7d9643c9176ff0bc2bf02f16b2b8ad82e3ab99a176539ce392acbf
|
data/lib/protobuf.rb
CHANGED
@@ -83,6 +83,19 @@ module Protobuf
|
|
83
83
|
@_print_deprecation_warnings = !!value
|
84
84
|
end
|
85
85
|
|
86
|
+
# Permit unknown field on Message initialization
|
87
|
+
#
|
88
|
+
# Default: true
|
89
|
+
#
|
90
|
+
# Simple boolean to define whether we want to permit unknown fields
|
91
|
+
# on Message intialization; otherwise a ::Protobuf::FieldNotDefinedError is thrown.
|
92
|
+
def self.ignore_unknown_fields?
|
93
|
+
!defined?(@_ignore_unknown_fields) || @_ignore_unknown_fields
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.ignore_unknown_fields=(value)
|
97
|
+
@_ignore_unknown_fields = !!value
|
98
|
+
end
|
86
99
|
end
|
87
100
|
|
88
101
|
unless ENV.key?('PB_NO_NETWORKING')
|
data/lib/protobuf/message.rb
CHANGED
@@ -30,7 +30,7 @@ module Protobuf
|
|
30
30
|
@values = {}
|
31
31
|
|
32
32
|
fields.to_hash.each_pair do |name, value|
|
33
|
-
self[name] = value
|
33
|
+
self[name] = value
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -135,7 +135,11 @@ module Protobuf
|
|
135
135
|
|
136
136
|
def []=(name, value)
|
137
137
|
if field = self.class.get_field(name, true)
|
138
|
-
__send__(field.setter_method_name, value)
|
138
|
+
__send__(field.setter_method_name, value) unless value.nil?
|
139
|
+
else
|
140
|
+
unless ::Protobuf.ignore_unknown_fields?
|
141
|
+
raise ::Protobuf::FieldNotDefinedError, name
|
142
|
+
end
|
139
143
|
end
|
140
144
|
end
|
141
145
|
|
data/lib/protobuf/version.rb
CHANGED
@@ -157,6 +157,55 @@ describe Protobuf::Message do
|
|
157
157
|
test_enum = Test::EnumTestMessage.new(hashie_object)
|
158
158
|
expect(test_enum.non_default_enum).to eq(2)
|
159
159
|
end
|
160
|
+
|
161
|
+
context 'ignoring unknown fields' do
|
162
|
+
before { ::Protobuf.ignore_unknown_fields = true }
|
163
|
+
|
164
|
+
context 'with valid fields' do
|
165
|
+
let(:values) { { :name => "Jim" } }
|
166
|
+
|
167
|
+
it "does not raise an error" do
|
168
|
+
expect { ::Test::Resource.new(values) }.to_not raise_error
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'with non-existent field' do
|
173
|
+
let(:values) { { :name => "Jim", :othername => "invalid" } }
|
174
|
+
|
175
|
+
it "does not raise an error" do
|
176
|
+
expect { ::Test::Resource.new(values) }.to_not raise_error
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context 'not ignoring unknown fields' do
|
182
|
+
before { ::Protobuf.ignore_unknown_fields = false }
|
183
|
+
after { ::Protobuf.ignore_unknown_fields = true }
|
184
|
+
|
185
|
+
context 'with valid fields' do
|
186
|
+
let(:values) { { :name => "Jim" } }
|
187
|
+
|
188
|
+
it "does not raise an error" do
|
189
|
+
expect { ::Test::Resource.new(values) }.to_not raise_error
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context 'with non-existent field' do
|
194
|
+
let(:values) { { :name => "Jim", :othername => "invalid" } }
|
195
|
+
|
196
|
+
it "raises an error and mentions the erroneous field" do
|
197
|
+
expect { ::Test::Resource.new(values) }.to raise_error(::Protobuf::FieldNotDefinedError, /othername/)
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'with a nil value' do
|
201
|
+
let(:values) { { :name => "Jim", :othername => nil } }
|
202
|
+
|
203
|
+
it "raises an error and mentions the erroneous field" do
|
204
|
+
expect { ::Test::Resource.new(values) }.to raise_error(::Protobuf::FieldNotDefinedError, /othername/)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
160
209
|
end
|
161
210
|
|
162
211
|
describe '#encode' do
|
data/spec/lib/protobuf_spec.rb
CHANGED
@@ -75,4 +75,24 @@ describe ::Protobuf do
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
describe '.ignore_unknown_fields?' do
|
79
|
+
before do
|
80
|
+
if described_class.instance_variable_defined?(:@_ignore_unknown_fields)
|
81
|
+
described_class.send(:remove_instance_variable, :@_ignore_unknown_fields)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'defaults to a true value' do
|
86
|
+
expect(described_class.ignore_unknown_fields?).to be true
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'is settable' do
|
90
|
+
expect {
|
91
|
+
described_class.ignore_unknown_fields = false
|
92
|
+
}.to change {
|
93
|
+
described_class.ignore_unknown_fields?
|
94
|
+
}.from(true).to(false)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
78
98
|
end
|
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.
|
4
|
+
version: 3.2.0
|
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: 2014-
|
14
|
+
date: 2014-08-01 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|