pbbuilder 0.16.2 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +5 -0
- data/lib/pbbuilder.rb +21 -8
- data/pbbuilder.gemspec +2 -2
- data/test/pbbuilder_test.rb +45 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75cb2682f8933e0e8acb2b3bb6a525df5447dab8a65b2d8509f54a3c2b430c35
|
4
|
+
data.tar.gz: '0282cfeb404460224fd8cb2d32d134335b9d307d2edefc4af854368b9c8788e1'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d429891ca19333b9e626ccd9bf63462fbe61eea672c8ac14f427aafdc392a2f12e36370e63f1a4522c384b4375e81433d63d804f447d508346744aedca448fbf
|
7
|
+
data.tar.gz: 1af6634160780c84f93a99d9b6b282e90500da24d654bfa36f1220b48260bec074412da69f83267a2df8f935e33218b332a27cf102765e6eff7b3db853ec686e
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
|
4
4
|
This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
5
5
|
|
6
|
+
## 0.17.0
|
7
|
+
### Changed
|
8
|
+
- Instead of appending to repeated enum message, we're replacing it to avoid issues in case output will be rendered twice
|
9
|
+
- If one field was defined twice, only last definition will end up in output
|
10
|
+
|
11
|
+
## Fixed
|
12
|
+
- Fixed CI by locking 3 version or lower of google-protobuf dependency.
|
13
|
+
|
6
14
|
## 0.16.2
|
7
15
|
### Added
|
8
16
|
- Add support for partial as a first argument , e.g.`pb.friends "racers/racer", as: :racer, collection: @racers`
|
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
@@ -75,25 +75,38 @@ class Pbbuilder
|
|
75
75
|
if arg.respond_to?(:to_hash)
|
76
76
|
# example syntax that should end up here:
|
77
77
|
# pb.fields {"one" => "two"}
|
78
|
+
|
78
79
|
arg.to_hash.each { |k, v| @message[name][k] = v }
|
79
80
|
elsif arg.respond_to?(:to_ary) && !descriptor.type.eql?(:message)
|
80
81
|
# pb.fields ["one", "two"]
|
81
|
-
# Using concat so it behaves the same as _append_repeated
|
82
82
|
|
83
|
-
@message[name].
|
83
|
+
@message[name].replace arg.to_ary
|
84
84
|
elsif arg.respond_to?(:to_ary) && descriptor.type.eql?(:message)
|
85
|
-
#
|
86
|
-
#
|
87
|
-
|
88
|
-
|
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
|
-
@message[name].
|
104
|
+
@message[name].replace [arg]
|
93
105
|
end
|
94
106
|
else
|
95
107
|
# example syntax that should end up here:
|
96
108
|
# pb.field "value"
|
109
|
+
|
97
110
|
@message[name] = arg
|
98
111
|
end
|
99
112
|
else
|
@@ -220,4 +233,4 @@ class Pbbuilder
|
|
220
233
|
message_class = message_descriptor.msgclass
|
221
234
|
message_class.new
|
222
235
|
end
|
223
|
-
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.
|
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"
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.files = `git ls-files`.split("\n")
|
15
15
|
spec.test_files = `git ls-files -- test/*`.split("\n")
|
16
16
|
|
17
|
-
spec.add_dependency "google-protobuf"
|
17
|
+
spec.add_dependency "google-protobuf", "~> 3.25"
|
18
18
|
spec.add_dependency "activesupport"
|
19
19
|
spec.add_development_dependency 'm'
|
20
20
|
spec.add_development_dependency "pry"
|
data/test/pbbuilder_test.rb
CHANGED
@@ -25,11 +25,55 @@ class PbbuilderTest < ActiveSupport::TestCase
|
|
25
25
|
|
26
26
|
assert_equal "Hello world", person.name
|
27
27
|
assert_equal "Friend #1", person.friends.first.name
|
28
|
-
assert_equal ["
|
28
|
+
assert_equal ["cool"], person.field_mask.paths
|
29
29
|
assert_equal "Manuelo", person.best_friend.name
|
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
|
+
|
50
|
+
test "replaces the repeated field's value with the last one set" do
|
51
|
+
person = Pbbuilder.new(API::Person.new) do |pb|
|
52
|
+
pb.field_mask do
|
53
|
+
pb.paths ["ok", "that's"]
|
54
|
+
end
|
55
|
+
end.target!
|
56
|
+
|
57
|
+
p = Pbbuilder.new(person) do |pb|
|
58
|
+
pb.field_mask do
|
59
|
+
pb.paths ["ok", "that's"]
|
60
|
+
end
|
61
|
+
end.target!
|
62
|
+
|
63
|
+
assert_equal(["ok", "that's"], p.field_mask.paths)
|
64
|
+
end
|
65
|
+
|
66
|
+
test "sets the last value of the repeated field to be the only value" do
|
67
|
+
person = Pbbuilder.new(API::Person.new) do |pb|
|
68
|
+
pb.field_mask do
|
69
|
+
pb.paths ["ok", "that's"]
|
70
|
+
pb.paths ["cool"]
|
71
|
+
end
|
72
|
+
end.target!
|
73
|
+
|
74
|
+
assert_equal ["cool"], person.field_mask.paths
|
75
|
+
end
|
76
|
+
|
33
77
|
test "it can extract fields in a nice way" do
|
34
78
|
klass = Struct.new(:name)
|
35
79
|
friends = [klass.new("Friend 1"), klass.new("Friend 2")]
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pbbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 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-
|
11
|
+
date: 2024-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-protobuf
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.25'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3.25'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
|
-
rubygems_version: 3.
|
126
|
+
rubygems_version: 3.3.7
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: Generate Protobuf Messages with a simple DSL similar to JBuilder
|