pbbuilder 0.17.0 → 0.18.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
  SHA256:
3
- metadata.gz: fe95820bf0015825b24715abe48a568f865affb04ec6c3db6261f33cd3e19829
4
- data.tar.gz: 0de697e6e0970a49cf599cb764e1941e019b1b6e0dddcc86c862c070a34ec904
3
+ metadata.gz: 75cb2682f8933e0e8acb2b3bb6a525df5447dab8a65b2d8509f54a3c2b430c35
4
+ data.tar.gz: '0282cfeb404460224fd8cb2d32d134335b9d307d2edefc4af854368b9c8788e1'
5
5
  SHA512:
6
- metadata.gz: fa06d08bee0e966095491d7b1d0956ff5c0f9a5d305fe66308c98883ddbe3c424d60b62ebf846fe25d2e7ec86181baf0666ec0d638648117188d1b17e3185784
7
- data.tar.gz: dac52c94458493380247cba47db06e61ad29590ff8b09b51abbe870aca8381f553870c16604b8079653488c0acc76fa87bfa54cb6a652e3c9fd0538e09ed85d8
6
+ metadata.gz: d429891ca19333b9e626ccd9bf63462fbe61eea672c8ac14f427aafdc392a2f12e36370e63f1a4522c384b4375e81433d63d804f447d508346744aedca448fbf
7
+ data.tar.gz: 1af6634160780c84f93a99d9b6b282e90500da24d654bfa36f1220b48260bec074412da69f83267a2df8f935e33218b332a27cf102765e6eff7b3db853ec686e
data/README.md CHANGED
@@ -4,6 +4,11 @@ PBBuilder generates [Protobuf](https://developers.google.com/protocol-buffers) M
4
4
 
5
5
  At least Rails 6.1 is required.
6
6
 
7
+ > [!WARNING]
8
+ > There currently is a regression in ActionView (the part of Rails which renders) that forces rendered objects into strings. This is only present
9
+ > in Rails 7.1, and is fixed in Rails. However, a 7.1 gem containing the fix hasn't been released yet. For the moment you should refrain
10
+ > from using pbbuilder and rails-twirp with Rails 7.1 and wait for the next version to be released.
11
+
7
12
  ## Compatibility with jBuilder
8
13
  We don't aim to have 100% compitability and coverage with jbuilder gem, but we closely follow jbuilder's API design to maintain familiarity.
9
14
 
data/lib/pbbuilder.rb CHANGED
@@ -82,14 +82,25 @@ class Pbbuilder
82
82
 
83
83
  @message[name].replace arg.to_ary
84
84
  elsif arg.respond_to?(:to_ary) && descriptor.type.eql?(:message)
85
- # example syntax that should end up here:
86
- # pb.friends [Person.new(name: "Johnny Test"), Person.new(name: "Max Verstappen")]
87
-
88
- args.flatten.each {|obj| @message[name].push descriptor.subtype.msgclass.new(obj)}
85
+ # pb.friends [Person.new(name: "Johnny Test"), Person.new(name: "Max Verstappen")]
86
+ #
87
+ # Accepts both objects that can be to_hash-translated into keyword arguments
88
+ # for creating a nested proto message object and actual proto message objects
89
+ # which can be assigned "as is". With "as-is" assignment the proto message can be stored
90
+ # in memory and reused
91
+ nested_messages = arg.map do |arg_member_message_or_hash|
92
+ # If the arg passed already is a proto message and is the same as the
93
+ # field expects - just use it as-is
94
+ if arg_member_message_or_hash.is_a?(descriptor.subtype.msgclass)
95
+ arg_member_message_or_hash
96
+ else
97
+ descriptor.subtype.msgclass.new(arg_member_message_or_hash)
98
+ end
99
+ end
100
+ @message[name].replace(nested_messages)
89
101
  else
90
102
  # example syntax that should end up here:
91
103
  # pb.fields "one"
92
-
93
104
  @message[name].replace [arg]
94
105
  end
95
106
  else
@@ -222,4 +233,4 @@ class Pbbuilder
222
233
  message_class = message_descriptor.msgclass
223
234
  message_class.new
224
235
  end
225
- end
236
+ end
data/pbbuilder.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "pbbuilder"
5
- spec.version = "0.17.0"
5
+ spec.version = "0.18.0"
6
6
  spec.authors = ["Bouke van der Bijl"]
7
7
  spec.email = ["bouke@cheddar.me"]
8
8
  spec.homepage = "https://github.com/cheddar-me/pbbuilder"
@@ -30,6 +30,23 @@ class PbbuilderTest < ActiveSupport::TestCase
30
30
  assert_equal "Eggs", person.favourite_foods["Breakfast"]
31
31
  end
32
32
 
33
+ test "allows assignment of prefab nested proto messages" do
34
+ max_proto = API::Person.new(name: "Max Verstappen")
35
+ james_proto = API::Person.new(name: "James Hunt")
36
+ friend_protos = [max_proto, james_proto]
37
+
38
+ person = Pbbuilder.new(API::Person.new) do |pb|
39
+ pb.name "Niki Lauda"
40
+ pb.friends friend_protos
41
+ pb.best_friend james_proto
42
+ end.target!
43
+
44
+ assert_equal "Niki Lauda", person.name
45
+ assert_equal "Max Verstappen", person.friends[0].name
46
+ assert_equal "James Hunt", person.friends[1].name
47
+ assert_equal "James Hunt", person.best_friend.name
48
+ end
49
+
33
50
  test "replaces the repeated field's value with the last one set" do
34
51
  person = Pbbuilder.new(API::Person.new) do |pb|
35
52
  pb.field_mask do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pbbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bouke van der Bijl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-22 00:00:00.000000000 Z
11
+ date: 2024-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf