prepor-beefcake 1.1.0.pre1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 915e8345407108ce58720d3ad23e18f213bf958e
4
- data.tar.gz: 134cfad1c7d35baa319d865f8746b8a39b85aea5
3
+ metadata.gz: b05eb3a8400e0af12563f45411a2e95cfb762ab6
4
+ data.tar.gz: ea1e377af18cbfb73ee824731e2ecbb0b3550d98
5
5
  SHA512:
6
- metadata.gz: 8fe0fad9ce257efb62ea6be7709fdbeee3121e0868213ab33765dbe7131d16a5ace2d48529815d8268f112304e3eedb9ddf9f0410e5613f4a7184fb21d2b8f8e
7
- data.tar.gz: cf2294ec52db492116034ba0290b0c2def5075f1ac7c9c7c44ce28ac7f68808b3928b518b1b471e66841f8c07e281b2428cfb29921c618ce8e58d477b9a685d5
6
+ metadata.gz: 21a7d5536ea0f5181357987ccfb8a9e4ff20757e2ee5e34a52b450d966cc62f5330b0d7b11c2aadbcbc92b22656d2afb8c1ed4ecd77ba9953deef87d8e46a052
7
+ data.tar.gz: 40ae3e963de1fbcad69d9f8b48fbdaf5bfdfbea1de6b99b8e8c3e8803487d965b142a24e27ddc5d76a95902c448627329571fba5cd0aa2d9b95d0e45b91343ae
data/.travis.yml CHANGED
@@ -3,13 +3,6 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - 2.1.0
6
- - 2.1.5
7
- - 2.2.0
6
+ - 2.1.1
7
+ - 2.1.2
8
8
  - jruby-19mode
9
- - rbx-2.2.7
10
- - ruby-head
11
- - jruby-head
12
- matrix:
13
- allow_failures:
14
- - rvm: jruby-head
15
- - rvm: ruby-head
data/lib/beefcake.rb CHANGED
@@ -33,18 +33,6 @@ module Beefcake
33
33
  def <=>(o)
34
34
  fn <=> o.fn
35
35
  end
36
-
37
- def same_type?(obj)
38
- type == obj
39
- end
40
-
41
- def is_protobuf?
42
- type.is_a?(Class) and type.include?(Beefcake::Message)
43
- end
44
-
45
- def required? ; rule == :required end
46
- def repeated? ; rule == :repeated end
47
- def optional? ; rule == :optional end
48
36
  end
49
37
 
50
38
 
@@ -197,8 +185,7 @@ module Beefcake
197
185
  end
198
186
  elsif fld.rule == :repeated
199
187
  val = buf.read(fld.type)
200
- o[fld.name] ||= []
201
- o[fld.name] << val
188
+ (o[fld.name] ||= []) << val
202
189
  else
203
190
  val = buf.read(fld.type)
204
191
  o[fld.name] = val
@@ -237,66 +224,10 @@ module Beefcake
237
224
  o.send(:include, Encode)
238
225
  end
239
226
 
240
- # (see #assign)
241
227
  def initialize(attrs={})
242
- assign attrs
243
- end
244
-
245
- # Handles filling a protobuf message from a hash. Embedded messages can
246
- # be passed in two ways, by a pure hash or as an instance of embedded class(es).
247
- #
248
- # @example By a pure hash.
249
- # {:field1 => 2, :embedded => {:embedded_f1 => 'lala'}}
250
- #
251
- # @example Repeated embedded message by a pure hash.
252
- # {:field1 => 2, :embedded => [
253
- # {:embedded_f1 => 'lala'},
254
- # {:embedded_f1 => 'lulu'}
255
- # ]}
256
- #
257
- # @example As an instance of embedded class.
258
- # {:field1 => 2, :embedded => EmbeddedMsg.new({:embedded_f1 => 'lala'})}
259
- #
260
- # @param [Hash] data to fill a protobuf message with.
261
- def assign(attrs)
262
228
  __beefcake_fields__.values.each do |fld|
263
- attribute = attrs[fld.name]
264
-
265
- if attribute.nil?
266
- self[fld.name] = nil
267
- next
268
- end
269
-
270
- unless fld.is_protobuf?
271
- self[fld.name] = attribute
272
- next
273
- end
274
-
275
- if fld.repeated? && attribute.is_a?(Hash)
276
- self[fld.name] = fld.type.new(attribute)
277
- next
278
- end
279
-
280
- if fld.repeated? && attribute.is_a?(fld.type)
281
- self[fld.name] = [attribute]
282
- next
283
- end
284
-
285
- if fld.repeated?
286
- self[fld.name] = attribute.map do |i|
287
- fld.same_type?(i) ? i : fld.type.new(i)
288
- end
289
- next
290
- end
291
-
292
- if fld.same_type? attribute
293
- self[fld.name] = attribute
294
- next
295
- end
296
-
297
- self[fld.name] = fld.type.new(attribute)
229
+ self[fld.name] = attrs[fld.name]
298
230
  end
299
- self
300
231
  end
301
232
 
302
233
  def __beefcake_fields__
@@ -339,22 +270,10 @@ module Beefcake
339
270
 
340
271
  def to_hash
341
272
  __beefcake_fields__.values.inject({}) do |h, fld|
342
- v = self[fld.name]
343
- next h if v.nil?
344
-
345
- h[fld.name] =
346
- case
347
- when v.respond_to?(:to_hash)
348
- # A nested protobuf message, so let's call its 'to_hash' method.
349
- v.to_hash
350
- when v.is_a?(Array)
351
- # There can be two field types stored in array.
352
- # Primitive type or nested another protobuf message.
353
- # The later one has got a 'to_hash' method.
354
- v.map { |i| i.respond_to?(:to_hash) ? i.to_hash : i }
355
- else
356
- v
357
- end
273
+ value = self[fld.name]
274
+ unless value.nil?
275
+ h[fld.name] = value
276
+ end
358
277
  h
359
278
  end
360
279
  end
@@ -140,10 +140,10 @@ module Beefcake
140
140
  T = CodeGeneratorRequest::FieldDescriptorProto::Type
141
141
 
142
142
 
143
- def self.compile(ns, req)
143
+ def self.compile(req)
144
144
  file = req.proto_file.map do |file|
145
145
  g = new(StringIO.new)
146
- g.compile(ns, file)
146
+ g.compile(file)
147
147
 
148
148
  g.c.rewind
149
149
  CodeGeneratorResponse::File.new(
@@ -266,7 +266,7 @@ module Beefcake
266
266
  puts "require \"beefcake\""
267
267
  puts
268
268
 
269
- ns!(package.split('.').map { |v| camelize(v) }) do
269
+ ns!(file.package.split('.').map { |v| camelize(v) }) do
270
270
  Array(file.enum_type).each do |et|
271
271
  enum!(et)
272
272
  end
@@ -1,3 +1,3 @@
1
1
  module Beefcake
2
- VERSION = "1.1.0.pre1"
2
+ VERSION = "1.1.0"
3
3
  end
data/test/message_test.rb CHANGED
@@ -102,70 +102,6 @@ class FieldsMessage
102
102
  repeated :fields, :string, 1
103
103
  end
104
104
 
105
- class FieldTest < Minitest::Test
106
- FIELD = Beefcake::Message::Field
107
-
108
- def test_required?
109
- f = FIELD.new :required, :field1, :string, 1
110
- assert f.required?
111
- refute f.optional?
112
- refute f.repeated?
113
-
114
- f = FIELD.new :optional, :field1, :int32, 1
115
- refute f.required?
116
-
117
- f = FIELD.new :repeated, :field1, :int32, 1
118
- refute f.required?
119
- end
120
-
121
- def test_optional?
122
- f = FIELD.new :optional, :field1, :string, 1
123
- assert f.optional?
124
- refute f.required?
125
- refute f.repeated?
126
-
127
- f = FIELD.new :required, :field1, :int32, 1
128
- refute f.optional?
129
-
130
- f = FIELD.new :repeated, :field1, :int32, 1
131
- refute f.optional?
132
- end
133
-
134
- def test_repeated?
135
- f = FIELD.new :repeated, :field1, :string, 1
136
- assert f.repeated?
137
- refute f.required?
138
- refute f.optional?
139
-
140
- f = FIELD.new :optional, :field1, :int32, 1
141
- refute f.repeated?
142
-
143
- f = FIELD.new :required, :field1, :int32, 1
144
- refute f.optional?
145
- end
146
-
147
- def test_same_type
148
- f = FIELD.new(:required, :field1, :int32, 1)
149
- assert f.same_type?(:int32)
150
- refute f.same_type?(:int64)
151
- refute f.same_type?(SimpleMessage)
152
-
153
- f = FIELD.new(:required, :field1, SimpleMessage, 1)
154
- assert f.same_type?(SimpleMessage)
155
- refute f.same_type?(:int32)
156
- refute f.same_type?(:string)
157
- refute f.same_type?(NumericsMessage)
158
- end
159
-
160
- def test_is_protobuf?
161
- f = FIELD.new(:required, :field1, SimpleMessage, 1)
162
- assert f.is_protobuf?
163
-
164
- f = FIELD.new(:required, :field1, :string, 1)
165
- refute f.is_protobuf?
166
- end
167
- end
168
-
169
105
  class MessageTest < Minitest::Test
170
106
  B = Beefcake::Buffer
171
107
 
@@ -227,12 +163,6 @@ class MessageTest < Minitest::Test
227
163
  )
228
164
 
229
165
  assert_equal buf2.to_s, msg.encode.to_s
230
-
231
- msg = CompositeMessage.new(
232
- :encodable => {:a => 123}
233
- )
234
- assert_equal buf2.to_s, msg.encode.to_s
235
-
236
166
  end
237
167
 
238
168
  def test_encode_to_string
@@ -266,9 +196,6 @@ class MessageTest < Minitest::Test
266
196
 
267
197
  msg = EnumsMessage.new :a => EnumsMessage::X::A
268
198
  assert_equal "\b\001", msg.encode.to_s
269
-
270
- msg = EnumsMessage.new :a => 1
271
- assert_equal "\b\001", msg.encode.to_s
272
199
  end
273
200
 
274
201
  def test_encode_invalid_enum_value
@@ -342,16 +269,6 @@ class MessageTest < Minitest::Test
342
269
  msg.encode.to_s
343
270
  end
344
271
 
345
- def test_repeated_with_hash
346
- before = { simple: { b: 'hello' } }
347
- RepeatedNestedMessage.new before
348
- end
349
-
350
- def test_repeated_with_scalar
351
- inner = SimpleMessage.new(b: 'hello')
352
- RepeatedNestedMessage.new simple: inner
353
- end
354
-
355
272
  ## Decoding
356
273
  def test_decode_numerics
357
274
  msg = NumericsMessage.new({
@@ -444,16 +361,6 @@ class MessageTest < Minitest::Test
444
361
  assert_equal 2, got.simple.size
445
362
  assert_equal 1, got.simple[0].a
446
363
  assert_equal "hello", got.simple[1].b
447
-
448
- simple_pure = [
449
- {:a => 1},
450
- {:b => "hello"}
451
- ]
452
- msg = RepeatedNestedMessage.new(:simple => simple_pure).encode
453
- got = RepeatedNestedMessage.decode(msg)
454
- assert_equal 2, got.simple.size
455
- assert_equal 1, got.simple[0].a
456
- assert_equal "hello", got.simple[1].b
457
364
  end
458
365
 
459
366
  def test_equality
@@ -502,23 +409,7 @@ class MessageTest < Minitest::Test
502
409
  def test_to_hash
503
410
  msg = SimpleMessage.new :a => 1
504
411
  exp = { :a => 1 }
505
- assert_equal exp, msg.to_hash
506
-
507
- msg = RepeatedNestedMessage.new(
508
- :simple => [
509
- SimpleMessage.new(:a => 1),
510
- SimpleMessage.new(:b => 'abc dfg'),
511
- SimpleMessage.new(:a => 2, :b => 'ijk lmn')
512
- ]
513
- )
514
- exp = {
515
- :simple =>[
516
- {:a => 1},
517
- {:b => 'abc dfg'},
518
- {:a => 2, :b => 'ijk lmn'}
519
- ]
520
- }
521
- assert_equal exp, msg.to_hash
412
+ assert_equal(exp, msg.to_hash)
522
413
  end
523
414
 
524
415
  def test_duplicate_index
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prepor-beefcake
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.pre1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Mizerany
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-04-03 00:00:00.000000000 Z
13
+ date: 2015-04-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -46,7 +46,7 @@ email:
46
46
  - matt.proud@gmail.com
47
47
  - bkerley@brycekerley.net
48
48
  executables:
49
- - protoc-gen-beefcake
49
+ - protoc-gen-prepor-beefcake
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
@@ -59,7 +59,7 @@ files:
59
59
  - Rakefile
60
60
  - beefcake.gemspec
61
61
  - bench/simple.rb
62
- - bin/protoc-gen-beefcake
62
+ - bin/protoc-gen-prepor-beefcake
63
63
  - dat/code_generator_request.dat
64
64
  - lib/beefcake.rb
65
65
  - lib/beefcake/buffer.rb
@@ -89,9 +89,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
89
  version: 1.9.3
90
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - ">"
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
- version: 1.3.1
94
+ version: '0'
95
95
  requirements: []
96
96
  rubyforge_project:
97
97
  rubygems_version: 2.4.3