pbbuilder 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pbbuilder.rb +16 -3
- data/pbbuilder.gemspec +1 -1
- data/test/pbbuilder_test.rb +11 -2
- data/test/test_helper.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ef756425a57d8ea7b70338e5d15f4de645a0fe43c6429a7bc83e601c3ae7730
|
4
|
+
data.tar.gz: 5c7579092048ee2b38f4aca3fa02c0c1490bb2f87a0ae58e9120672ca78b2de7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f963451d5430510700378384d0a996ad6eb15e311dc3669d8246122c2db7e65a0bb9b50b63855b18da1cf5f1484a57f85ad3eda95b3647f09438d04fc78d0e9
|
7
|
+
data.tar.gz: 52d88436c2f78dbe307f2ce87935a03c293a6ee68d2c471c993ef753166f7450380bf600f759b2d4d5467c5167a50d93dcb63d145085f8bf50acbcdc43531bd1
|
data/lib/pbbuilder.rb
CHANGED
@@ -44,7 +44,7 @@ class Pbbuilder < BasicObject
|
|
44
44
|
raise ::ArgumentError, "can't pass block to non-message field" unless descriptor.type == :message
|
45
45
|
|
46
46
|
if descriptor.label == :repeated
|
47
|
-
# pb.field @array { |element| pb.name
|
47
|
+
# pb.field @array { |element| pb.name element.name }
|
48
48
|
raise ::ArgumentError, "wrong number of arguments (expected 1)" unless args.length == 1
|
49
49
|
collection = args.first
|
50
50
|
_append_repeated(name, descriptor, collection, &block)
|
@@ -52,11 +52,24 @@ class Pbbuilder < BasicObject
|
|
52
52
|
end
|
53
53
|
|
54
54
|
raise ::ArgumentError, "wrong number of arguments (expected 0)" unless args.empty?
|
55
|
-
# pb.field { pb.name
|
55
|
+
# pb.field { pb.name "hello" }
|
56
56
|
message = (@message[name] ||= _new_message_from_descriptor(descriptor))
|
57
57
|
_scope(message, &block)
|
58
58
|
elsif args.length == 1
|
59
|
-
|
59
|
+
arg = args.first
|
60
|
+
if descriptor.label == :repeated
|
61
|
+
if arg.respond_to?(:to_ary)
|
62
|
+
# pb.fields ["one", "two"]
|
63
|
+
# Using concat so it behaves the same as _append_repeated
|
64
|
+
@message[name].concat arg.to_ary
|
65
|
+
else
|
66
|
+
# pb.fields "one"
|
67
|
+
@message[name].push arg
|
68
|
+
end
|
69
|
+
else
|
70
|
+
# pb.field "value"
|
71
|
+
@message[name] = arg
|
72
|
+
end
|
60
73
|
else
|
61
74
|
# pb.field @value, :id, :name, :url
|
62
75
|
element = args.shift
|
data/pbbuilder.gemspec
CHANGED
data/test/pbbuilder_test.rb
CHANGED
@@ -7,9 +7,18 @@ class PbbuilderTest < ActiveSupport::TestCase
|
|
7
7
|
pb.friends 1..3 do |number|
|
8
8
|
pb.name "Friend ##{number}"
|
9
9
|
end
|
10
|
+
pb.best_friend do
|
11
|
+
pb.name "Manuelo"
|
12
|
+
end
|
13
|
+
pb.field_mask do
|
14
|
+
pb.paths ["ok", "that's"]
|
15
|
+
pb.paths "cool"
|
16
|
+
end
|
10
17
|
end.target!
|
11
|
-
assert_equal
|
12
|
-
assert_equal person.friends.first.name
|
18
|
+
assert_equal "Hello world", person.name
|
19
|
+
assert_equal "Friend #1", person.friends.first.name
|
20
|
+
assert_equal ["ok", "that's", "cool"], person.field_mask.paths
|
21
|
+
assert_equal "Manuelo", person.best_friend.name
|
13
22
|
end
|
14
23
|
|
15
24
|
test "it can extract fields in a nice way" do
|
data/test/test_helper.rb
CHANGED
@@ -9,6 +9,7 @@ require "pbbuilder"
|
|
9
9
|
Rails::TestUnitReporter.executable = "bin/test"
|
10
10
|
|
11
11
|
require "google/protobuf"
|
12
|
+
require "google/protobuf/field_mask_pb"
|
12
13
|
|
13
14
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
14
15
|
add_file("pbbuilder.proto", syntax: :proto3) do
|
@@ -16,6 +17,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
16
17
|
optional :name, :string, 1
|
17
18
|
repeated :friends, :message, 2, "pbbuildertest.Person"
|
18
19
|
optional :best_friend, :message, 3, "pbbuildertest.Person"
|
20
|
+
repeated :nicknames, :string, 4
|
21
|
+
optional :field_mask, :message, 5, "google.protobuf.FieldMask"
|
19
22
|
end
|
20
23
|
end
|
21
24
|
end
|
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.
|
4
|
+
version: 0.5.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: 2021-04-
|
11
|
+
date: 2021-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-protobuf
|