protip 0.19.0 → 0.19.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c710d883e4cf3fb67e30f0038db21c584a17bacb
|
4
|
+
data.tar.gz: ae3837edd3f0c189bdc6e7d913b6fef0b545d303
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01c9c0534123cc276cf12ccfcb20fb43901ae947091168d726797ea1a8951bbff0b437168fef560fd69f74077baac8e0063ac1edc958ca567c5c5760e094d67b
|
7
|
+
data.tar.gz: 2f30d7481ba416358e644b0073653b2af239c1e911483e758104a60df7f6779c8993486244061b17c5dc14b40ed39d0257ea5ce185089ff4ed2582b2cdab5c59
|
@@ -0,0 +1,39 @@
|
|
1
|
+
syntax = "proto3";
|
2
|
+
|
3
|
+
package protip.messages;
|
4
|
+
|
5
|
+
message RepeatedDouble {
|
6
|
+
repeated double values = 1;
|
7
|
+
}
|
8
|
+
|
9
|
+
message RepeatedFloat {
|
10
|
+
repeated float values = 1;
|
11
|
+
}
|
12
|
+
|
13
|
+
message RepeatedInt64 {
|
14
|
+
repeated int64 values = 1;
|
15
|
+
}
|
16
|
+
|
17
|
+
message RepeatedUInt64 {
|
18
|
+
repeated uint64 values = 1;
|
19
|
+
}
|
20
|
+
|
21
|
+
message RepeatedInt32 {
|
22
|
+
repeated int32 values = 1;
|
23
|
+
}
|
24
|
+
|
25
|
+
message RepeatedUInt32 {
|
26
|
+
repeated uint32 values = 1;
|
27
|
+
}
|
28
|
+
|
29
|
+
message RepeatedBool {
|
30
|
+
repeated bool values = 1;
|
31
|
+
}
|
32
|
+
|
33
|
+
message RepeatedString {
|
34
|
+
repeated string values = 1;
|
35
|
+
}
|
36
|
+
|
37
|
+
message RepeatedBytes {
|
38
|
+
repeated bytes values = 1;
|
39
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: protip/messages/repeated.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
+
add_message "protip.messages.RepeatedDouble" do
|
8
|
+
repeated :values, :double, 1
|
9
|
+
end
|
10
|
+
add_message "protip.messages.RepeatedFloat" do
|
11
|
+
repeated :values, :float, 1
|
12
|
+
end
|
13
|
+
add_message "protip.messages.RepeatedInt64" do
|
14
|
+
repeated :values, :int64, 1
|
15
|
+
end
|
16
|
+
add_message "protip.messages.RepeatedUInt64" do
|
17
|
+
repeated :values, :uint64, 1
|
18
|
+
end
|
19
|
+
add_message "protip.messages.RepeatedInt32" do
|
20
|
+
repeated :values, :int32, 1
|
21
|
+
end
|
22
|
+
add_message "protip.messages.RepeatedUInt32" do
|
23
|
+
repeated :values, :uint32, 1
|
24
|
+
end
|
25
|
+
add_message "protip.messages.RepeatedBool" do
|
26
|
+
repeated :values, :bool, 1
|
27
|
+
end
|
28
|
+
add_message "protip.messages.RepeatedString" do
|
29
|
+
repeated :values, :string, 1
|
30
|
+
end
|
31
|
+
add_message "protip.messages.RepeatedBytes" do
|
32
|
+
repeated :values, :bytes, 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module Protip
|
37
|
+
module Messages
|
38
|
+
RepeatedDouble = Google::Protobuf::DescriptorPool.generated_pool.lookup("protip.messages.RepeatedDouble").msgclass
|
39
|
+
RepeatedFloat = Google::Protobuf::DescriptorPool.generated_pool.lookup("protip.messages.RepeatedFloat").msgclass
|
40
|
+
RepeatedInt64 = Google::Protobuf::DescriptorPool.generated_pool.lookup("protip.messages.RepeatedInt64").msgclass
|
41
|
+
RepeatedUInt64 = Google::Protobuf::DescriptorPool.generated_pool.lookup("protip.messages.RepeatedUInt64").msgclass
|
42
|
+
RepeatedInt32 = Google::Protobuf::DescriptorPool.generated_pool.lookup("protip.messages.RepeatedInt32").msgclass
|
43
|
+
RepeatedUInt32 = Google::Protobuf::DescriptorPool.generated_pool.lookup("protip.messages.RepeatedUInt32").msgclass
|
44
|
+
RepeatedBool = Google::Protobuf::DescriptorPool.generated_pool.lookup("protip.messages.RepeatedBool").msgclass
|
45
|
+
RepeatedString = Google::Protobuf::DescriptorPool.generated_pool.lookup("protip.messages.RepeatedString").msgclass
|
46
|
+
RepeatedBytes = Google::Protobuf::DescriptorPool.generated_pool.lookup("protip.messages.RepeatedBytes").msgclass
|
47
|
+
end
|
48
|
+
end
|
@@ -7,6 +7,7 @@ require 'protip/converter'
|
|
7
7
|
require 'protip/messages/currency'
|
8
8
|
require 'protip/messages/money'
|
9
9
|
require 'protip/messages/range'
|
10
|
+
require 'protip/messages/repeated'
|
10
11
|
require 'protip/messages/types'
|
11
12
|
require 'google/protobuf'
|
12
13
|
module Protip
|
@@ -57,13 +58,19 @@ module Protip
|
|
57
58
|
}
|
58
59
|
|
59
60
|
## Standard wrappers
|
60
|
-
%w(Int64 Int32 UInt64 UInt32 Double Float String Bytes).
|
61
|
-
@conversions[
|
61
|
+
%w(Int64 Int32 UInt64 UInt32 Double Float String Bytes).each do |type|
|
62
|
+
@conversions["google.protobuf.#{type}Value"] = {
|
62
63
|
to_object: ->(message) { message.value },
|
63
64
|
to_message: lambda do |value, message_class|
|
64
65
|
message_class.new value: value
|
65
66
|
end
|
66
67
|
}
|
68
|
+
@conversions["protip.messages.Repeated#{type}"] = {
|
69
|
+
to_object: ->(message) { message.values.to_a.freeze },
|
70
|
+
to_message: lambda do |value, message_class|
|
71
|
+
message_class.new values: (value.is_a?(Enumerable) ? value : [value])
|
72
|
+
end
|
73
|
+
}
|
67
74
|
end
|
68
75
|
|
69
76
|
conversions['google.protobuf.BoolValue'] = {
|
@@ -73,6 +80,14 @@ module Protip
|
|
73
80
|
end
|
74
81
|
}
|
75
82
|
|
83
|
+
conversions['protip.messages.RepeatedBool'] = {
|
84
|
+
to_object: ->(message) { message.values.to_a.freeze },
|
85
|
+
to_message: lambda do |value, message_class|
|
86
|
+
message_class.new values: (value.is_a?(Enumerable) ? value : [value]).map{|v| value_to_boolean(v)}
|
87
|
+
end
|
88
|
+
|
89
|
+
}
|
90
|
+
|
76
91
|
## ActiveSupport objects
|
77
92
|
conversions['protip.messages.ActiveSupport.TimeWithZone'] = {
|
78
93
|
to_object: ->(message) {
|
@@ -17,6 +17,15 @@ describe Protip::StandardConverter do
|
|
17
17
|
]
|
18
18
|
end
|
19
19
|
|
20
|
+
let(:repeated_integer_types) do
|
21
|
+
[
|
22
|
+
Protip::Messages::RepeatedInt64,
|
23
|
+
Protip::Messages::RepeatedInt32,
|
24
|
+
Protip::Messages::RepeatedUInt64,
|
25
|
+
Protip::Messages::RepeatedUInt32,
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
20
29
|
let(:float_types) do
|
21
30
|
[
|
22
31
|
Google::Protobuf::FloatValue,
|
@@ -24,18 +33,37 @@ describe Protip::StandardConverter do
|
|
24
33
|
]
|
25
34
|
end
|
26
35
|
|
36
|
+
let(:repeated_float_types) do
|
37
|
+
[
|
38
|
+
Protip::Messages::RepeatedFloat,
|
39
|
+
Protip::Messages::RepeatedDouble,
|
40
|
+
]
|
41
|
+
end
|
42
|
+
|
27
43
|
let(:bool_types) do
|
28
44
|
[Google::Protobuf::BoolValue]
|
29
45
|
end
|
30
46
|
|
47
|
+
let(:repeated_bool_types) do
|
48
|
+
[Protip::Messages::RepeatedBool]
|
49
|
+
end
|
50
|
+
|
31
51
|
let(:string_types) do
|
32
52
|
[Google::Protobuf::StringValue]
|
33
53
|
end
|
34
54
|
|
55
|
+
let(:repeated_string_types) do
|
56
|
+
[Protip::Messages::RepeatedString]
|
57
|
+
end
|
58
|
+
|
35
59
|
let(:bytes_types) do
|
36
60
|
[Google::Protobuf::BytesValue]
|
37
61
|
end
|
38
62
|
|
63
|
+
let(:repeated_bytes_types) do
|
64
|
+
[Protip::Messages::RepeatedBytes]
|
65
|
+
end
|
66
|
+
|
39
67
|
let(:protip_types) do
|
40
68
|
[
|
41
69
|
Protip::Messages::Range,
|
@@ -45,9 +73,16 @@ describe Protip::StandardConverter do
|
|
45
73
|
]
|
46
74
|
end
|
47
75
|
|
76
|
+
let(:integer_value) { 6 }
|
77
|
+
let(:float_value) { 5.5 }
|
78
|
+
let(:bool_value) { true }
|
79
|
+
let(:string_value) { 'asdf' }
|
80
|
+
let(:bytes_value) { Base64.decode64("U2VuZCByZWluZm9yY2VtZW50cw==\n") }
|
81
|
+
|
48
82
|
describe '#convertible?' do
|
49
83
|
it 'converts all standard types' do
|
50
|
-
(integer_types + float_types + string_types + bool_types + protip_types
|
84
|
+
(integer_types + float_types + string_types + bool_types + protip_types + repeated_integer_types +
|
85
|
+
repeated_float_types + repeated_string_types + repeated_bool_types).each do |message_class|
|
51
86
|
assert converter.convertible?(message_class), "expected type #{message_class.descriptor.name} not convertible"
|
52
87
|
end
|
53
88
|
end
|
@@ -62,11 +97,11 @@ describe Protip::StandardConverter do
|
|
62
97
|
describe '#to_object' do
|
63
98
|
it 'converts wrapper types' do
|
64
99
|
{
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
100
|
+
integer_value => integer_types,
|
101
|
+
float_value => float_types,
|
102
|
+
bool_value => bool_types,
|
103
|
+
string_value => string_types,
|
104
|
+
bytes_value => bytes_types,
|
70
105
|
}.each do |value, message_types|
|
71
106
|
message_types.each do |message_class|
|
72
107
|
assert_equal value, converter.to_object(message_class.new value: value)
|
@@ -74,6 +109,25 @@ describe Protip::StandardConverter do
|
|
74
109
|
end
|
75
110
|
end
|
76
111
|
|
112
|
+
it 'converts repeated types to an immutable array' do
|
113
|
+
{
|
114
|
+
integer_value => repeated_integer_types,
|
115
|
+
float_value => repeated_float_types,
|
116
|
+
bool_value => repeated_bool_types,
|
117
|
+
string_value => repeated_string_types,
|
118
|
+
bytes_value => repeated_bytes_types,
|
119
|
+
}.each do |value, message_types|
|
120
|
+
message_types.each do |message_class|
|
121
|
+
result = converter.to_object(message_class.new values: [value])
|
122
|
+
assert_equal [value], result
|
123
|
+
exception = assert_raises RuntimeError do
|
124
|
+
result << value
|
125
|
+
end
|
126
|
+
assert_equal 'can\'t modify frozen Array', exception.message
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
77
131
|
it 'converts dates' do
|
78
132
|
date = converter.to_object(::Protip::Messages::Date.new year: 2015, month: 2, day: 9)
|
79
133
|
assert_instance_of ::Date, date
|
@@ -114,11 +168,11 @@ describe Protip::StandardConverter do
|
|
114
168
|
describe '#to_message' do
|
115
169
|
it 'converts wrapper types' do
|
116
170
|
{
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
171
|
+
integer_value => integer_types,
|
172
|
+
float_value => float_types,
|
173
|
+
bool_value => bool_types,
|
174
|
+
string_value => string_types,
|
175
|
+
bytes_value => bytes_types,
|
122
176
|
}.each do |value, message_types|
|
123
177
|
message_types.each do |message_class|
|
124
178
|
assert_equal message_class.new(value: value), converter.to_message(value, message_class)
|
@@ -126,6 +180,34 @@ describe Protip::StandardConverter do
|
|
126
180
|
end
|
127
181
|
end
|
128
182
|
|
183
|
+
it 'converts repeated types when set with a scalar value' do
|
184
|
+
{
|
185
|
+
integer_value => repeated_integer_types,
|
186
|
+
float_value => repeated_float_types,
|
187
|
+
bool_value => repeated_bool_types,
|
188
|
+
string_value => repeated_string_types,
|
189
|
+
bytes_value => repeated_bytes_types,
|
190
|
+
}.each do |value, message_types|
|
191
|
+
message_types.each do |message_class|
|
192
|
+
assert_equal message_class.new(values: [value]), converter.to_message(value, message_class)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'converts repeated types when set with an enumerable value' do
|
198
|
+
{
|
199
|
+
integer_value => repeated_integer_types,
|
200
|
+
float_value => repeated_float_types,
|
201
|
+
bool_value => repeated_bool_types,
|
202
|
+
string_value => repeated_string_types,
|
203
|
+
bytes_value => repeated_bytes_types,
|
204
|
+
}.each do |value, message_types|
|
205
|
+
message_types.each do |message_class|
|
206
|
+
assert_equal message_class.new(values: [value, value]), converter.to_message([value, value], message_class)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
129
211
|
it 'converts dates' do
|
130
212
|
date = ::Date.new(2012, 5, 7)
|
131
213
|
assert_equal 7, date.day # Sanity check argument order
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.19.
|
4
|
+
version: 0.19.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AngelList
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -199,6 +199,7 @@ files:
|
|
199
199
|
- definitions/protip/messages/errors.proto
|
200
200
|
- definitions/protip/messages/money.proto
|
201
201
|
- definitions/protip/messages/range.proto
|
202
|
+
- definitions/protip/messages/repeated.proto
|
202
203
|
- definitions/protip/messages/types.proto
|
203
204
|
- lib/google/protobuf/wrappers.rb
|
204
205
|
- lib/protip.rb
|
@@ -211,6 +212,7 @@ files:
|
|
211
212
|
- lib/protip/messages/errors.rb
|
212
213
|
- lib/protip/messages/money.rb
|
213
214
|
- lib/protip/messages/range.rb
|
215
|
+
- lib/protip/messages/repeated.rb
|
214
216
|
- lib/protip/messages/types.rb
|
215
217
|
- lib/protip/resource.rb
|
216
218
|
- lib/protip/resource/associations/association.rb
|