protip 0.20.7 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/protip.rb +10 -0
- data/lib/protip/{wrapper.rb → decorator.rb} +98 -82
- data/lib/protip/extensions.rb +0 -1
- data/lib/protip/resource.rb +56 -32
- data/lib/protip/resource/extra_methods.rb +5 -3
- data/lib/protip/tasks/compile.rake +2 -2
- data/lib/protip/transformer.rb +14 -0
- data/lib/protip/transformers/abstract_transformer.rb +11 -0
- data/lib/protip/transformers/active_support/time_with_zone_transformer.rb +35 -0
- data/lib/protip/transformers/decorating_transformer.rb +33 -0
- data/lib/protip/transformers/default_transformer.rb +22 -0
- data/lib/protip/transformers/delegating_transformer.rb +44 -0
- data/lib/protip/transformers/deprecated_transformer.rb +90 -0
- data/lib/protip/transformers/enum_transformer.rb +93 -0
- data/lib/protip/transformers/primitives_transformer.rb +78 -0
- data/lib/protip/transformers/timestamp_transformer.rb +31 -0
- data/test/functional/protip/decorator_test.rb +204 -0
- data/test/unit/protip/decorator_test.rb +665 -0
- data/test/unit/protip/resource_test.rb +76 -92
- data/test/unit/protip/transformers/decorating_transformer_test.rb +92 -0
- data/test/unit/protip/transformers/delegating_transformer_test.rb +83 -0
- data/test/unit/protip/transformers/deprecated_transformer_test.rb +139 -0
- data/test/unit/protip/transformers/enum_transformer_test.rb +157 -0
- data/test/unit/protip/transformers/primitives_transformer_test.rb +139 -0
- data/test/unit/protip/transformers/timestamp_transformer_test.rb +46 -0
- metadata +23 -12
- data/definitions/google/protobuf/wrappers.proto +0 -99
- data/lib/google/protobuf/descriptor.rb +0 -1
- data/lib/google/protobuf/wrappers.rb +0 -48
- data/lib/protip/converter.rb +0 -22
- data/lib/protip/standard_converter.rb +0 -185
- data/test/unit/protip/standard_converter_test.rb +0 -502
- data/test/unit/protip/wrapper_test.rb +0 -646
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.
|
4
|
+
version: 0.30.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AngelList
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -54,14 +54,14 @@ dependencies:
|
|
54
54
|
name: google-protobuf
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
|
-
- -
|
57
|
+
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: 3.0.0.alpha.5.0.5.1
|
60
60
|
type: :runtime
|
61
61
|
prerelease: false
|
62
62
|
version_requirements: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
|
-
- -
|
64
|
+
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: 3.0.0.alpha.5.0.5.1
|
67
67
|
- !ruby/object:Gem::Dependency
|
@@ -178,7 +178,6 @@ executables: []
|
|
178
178
|
extensions: []
|
179
179
|
extra_rdoc_files: []
|
180
180
|
files:
|
181
|
-
- definitions/google/protobuf/wrappers.proto
|
182
181
|
- definitions/protip/extensions.proto
|
183
182
|
- definitions/protip/messages.proto
|
184
183
|
- definitions/protip/messages/active_support/time_with_zone.proto
|
@@ -191,11 +190,9 @@ files:
|
|
191
190
|
- definitions/protip/messages/test.proto
|
192
191
|
- definitions/protip/messages/types.proto
|
193
192
|
- definitions/protip/messages/wrappers.proto
|
194
|
-
- lib/google/protobuf/descriptor.rb
|
195
|
-
- lib/google/protobuf/wrappers.rb
|
196
193
|
- lib/protip.rb
|
197
194
|
- lib/protip/client.rb
|
198
|
-
- lib/protip/
|
195
|
+
- lib/protip/decorator.rb
|
199
196
|
- lib/protip/error.rb
|
200
197
|
- lib/protip/extensions.rb
|
201
198
|
- lib/protip/messages.rb
|
@@ -218,17 +215,31 @@ files:
|
|
218
215
|
- lib/protip/resource/extra_methods.rb
|
219
216
|
- lib/protip/resource/search_methods.rb
|
220
217
|
- lib/protip/resource/updateable.rb
|
221
|
-
- lib/protip/standard_converter.rb
|
222
218
|
- lib/protip/tasks/compile.rake
|
223
|
-
- lib/protip/
|
219
|
+
- lib/protip/transformer.rb
|
220
|
+
- lib/protip/transformers/abstract_transformer.rb
|
221
|
+
- lib/protip/transformers/active_support/time_with_zone_transformer.rb
|
222
|
+
- lib/protip/transformers/decorating_transformer.rb
|
223
|
+
- lib/protip/transformers/default_transformer.rb
|
224
|
+
- lib/protip/transformers/delegating_transformer.rb
|
225
|
+
- lib/protip/transformers/deprecated_transformer.rb
|
226
|
+
- lib/protip/transformers/enum_transformer.rb
|
227
|
+
- lib/protip/transformers/primitives_transformer.rb
|
228
|
+
- lib/protip/transformers/timestamp_transformer.rb
|
229
|
+
- test/functional/protip/decorator_test.rb
|
224
230
|
- test/functional/protip/resource_test.rb
|
225
231
|
- test/test_helper.rb
|
232
|
+
- test/unit/protip/decorator_test.rb
|
226
233
|
- test/unit/protip/resource/associations/association_test.rb
|
227
234
|
- test/unit/protip/resource/associations/belongs_to_association_test.rb
|
228
235
|
- test/unit/protip/resource/associations/belongs_to_polymorphic_association_test.rb
|
229
236
|
- test/unit/protip/resource_test.rb
|
230
|
-
- test/unit/protip/
|
231
|
-
- test/unit/protip/
|
237
|
+
- test/unit/protip/transformers/decorating_transformer_test.rb
|
238
|
+
- test/unit/protip/transformers/delegating_transformer_test.rb
|
239
|
+
- test/unit/protip/transformers/deprecated_transformer_test.rb
|
240
|
+
- test/unit/protip/transformers/enum_transformer_test.rb
|
241
|
+
- test/unit/protip/transformers/primitives_transformer_test.rb
|
242
|
+
- test/unit/protip/transformers/timestamp_transformer_test.rb
|
232
243
|
homepage: https://github.com/AngelList/protip
|
233
244
|
licenses:
|
234
245
|
- MIT
|
@@ -1,99 +0,0 @@
|
|
1
|
-
// Protocol Buffers - Google's data interchange format
|
2
|
-
// Copyright 2008 Google Inc. All rights reserved.
|
3
|
-
// https://developers.google.com/protocol-buffers/
|
4
|
-
//
|
5
|
-
// Redistribution and use in source and binary forms, with or without
|
6
|
-
// modification, are permitted provided that the following conditions are
|
7
|
-
// met:
|
8
|
-
//
|
9
|
-
// * Redistributions of source code must retain the above copyright
|
10
|
-
// notice, this list of conditions and the following disclaimer.
|
11
|
-
// * Redistributions in binary form must reproduce the above
|
12
|
-
// copyright notice, this list of conditions and the following disclaimer
|
13
|
-
// in the documentation and/or other materials provided with the
|
14
|
-
// distribution.
|
15
|
-
// * Neither the name of Google Inc. nor the names of its
|
16
|
-
// contributors may be used to endorse or promote products derived from
|
17
|
-
// this software without specific prior written permission.
|
18
|
-
//
|
19
|
-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
20
|
-
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
21
|
-
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
22
|
-
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
-
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
-
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
25
|
-
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
26
|
-
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
27
|
-
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
-
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
-
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
-
|
31
|
-
// Wrappers for primitive (non-message) types. These types are useful
|
32
|
-
// for embedding primitives in the `google.protobuf.Any` type and for places
|
33
|
-
// where we need to distinguish between the absence of a primitive
|
34
|
-
// typed field and its default value.
|
35
|
-
|
36
|
-
syntax = "proto3";
|
37
|
-
|
38
|
-
package google.protobuf;
|
39
|
-
|
40
|
-
option java_multiple_files = true;
|
41
|
-
option java_outer_classname = "WrappersProto";
|
42
|
-
option java_package = "com.google.protobuf";
|
43
|
-
option csharp_namespace = "Google.Protobuf.WellKnownTypes";
|
44
|
-
option objc_class_prefix = "GPB";
|
45
|
-
|
46
|
-
|
47
|
-
// Wrapper message for double.
|
48
|
-
message DoubleValue {
|
49
|
-
// The double value.
|
50
|
-
double value = 1;
|
51
|
-
}
|
52
|
-
|
53
|
-
// Wrapper message for float.
|
54
|
-
message FloatValue {
|
55
|
-
// The float value.
|
56
|
-
float value = 1;
|
57
|
-
}
|
58
|
-
|
59
|
-
// Wrapper message for int64.
|
60
|
-
message Int64Value {
|
61
|
-
// The int64 value.
|
62
|
-
int64 value = 1;
|
63
|
-
}
|
64
|
-
|
65
|
-
// Wrapper message for uint64.
|
66
|
-
message UInt64Value {
|
67
|
-
// The uint64 value.
|
68
|
-
uint64 value = 1;
|
69
|
-
}
|
70
|
-
|
71
|
-
// Wrapper message for int32.
|
72
|
-
message Int32Value {
|
73
|
-
// The int32 value.
|
74
|
-
int32 value = 1;
|
75
|
-
}
|
76
|
-
|
77
|
-
// Wrapper message for uint32.
|
78
|
-
message UInt32Value {
|
79
|
-
// The uint32 value.
|
80
|
-
uint32 value = 1;
|
81
|
-
}
|
82
|
-
|
83
|
-
// Wrapper message for bool.
|
84
|
-
message BoolValue {
|
85
|
-
// The bool value.
|
86
|
-
bool value = 1;
|
87
|
-
}
|
88
|
-
|
89
|
-
// Wrapper message for string.
|
90
|
-
message StringValue {
|
91
|
-
// The string value.
|
92
|
-
string value = 1;
|
93
|
-
}
|
94
|
-
|
95
|
-
// Wrapper message for bytes.
|
96
|
-
message BytesValue {
|
97
|
-
// The bytes value.
|
98
|
-
bytes value = 1;
|
99
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
# Placeholder file until Google rolls google/protobuf/descriptor into the gem
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
-
# source: google/protobuf/wrappers.proto
|
3
|
-
|
4
|
-
require 'google/protobuf'
|
5
|
-
|
6
|
-
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
-
add_message "google.protobuf.DoubleValue" do
|
8
|
-
optional :value, :double, 1
|
9
|
-
end
|
10
|
-
add_message "google.protobuf.FloatValue" do
|
11
|
-
optional :value, :float, 1
|
12
|
-
end
|
13
|
-
add_message "google.protobuf.Int64Value" do
|
14
|
-
optional :value, :int64, 1
|
15
|
-
end
|
16
|
-
add_message "google.protobuf.UInt64Value" do
|
17
|
-
optional :value, :uint64, 1
|
18
|
-
end
|
19
|
-
add_message "google.protobuf.Int32Value" do
|
20
|
-
optional :value, :int32, 1
|
21
|
-
end
|
22
|
-
add_message "google.protobuf.UInt32Value" do
|
23
|
-
optional :value, :uint32, 1
|
24
|
-
end
|
25
|
-
add_message "google.protobuf.BoolValue" do
|
26
|
-
optional :value, :bool, 1
|
27
|
-
end
|
28
|
-
add_message "google.protobuf.StringValue" do
|
29
|
-
optional :value, :string, 1
|
30
|
-
end
|
31
|
-
add_message "google.protobuf.BytesValue" do
|
32
|
-
optional :value, :bytes, 1
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
module Google
|
37
|
-
module Protobuf
|
38
|
-
DoubleValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DoubleValue").msgclass
|
39
|
-
FloatValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FloatValue").msgclass
|
40
|
-
Int64Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int64Value").msgclass
|
41
|
-
UInt64Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt64Value").msgclass
|
42
|
-
Int32Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int32Value").msgclass
|
43
|
-
UInt32Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt32Value").msgclass
|
44
|
-
BoolValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BoolValue").msgclass
|
45
|
-
StringValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.StringValue").msgclass
|
46
|
-
BytesValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BytesValue").msgclass
|
47
|
-
end
|
48
|
-
end
|
data/lib/protip/converter.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
|
3
|
-
|
4
|
-
module Protip
|
5
|
-
module Converter
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
def convertible?(message_class)
|
9
|
-
raise NotImplementedError.new(
|
10
|
-
'Must specify whether a message of a given type can be converted to/from a Ruby object'
|
11
|
-
)
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_object(message, field)
|
15
|
-
raise NotImplementedError.new('Must convert a message into a Ruby object')
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_message(object, message_class, field)
|
19
|
-
raise NotImplementedError.new('Must convert a Ruby object into a message of the given type')
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,185 +0,0 @@
|
|
1
|
-
require 'money'
|
2
|
-
|
3
|
-
require 'active_support/time_with_zone'
|
4
|
-
|
5
|
-
require 'protip/converter'
|
6
|
-
|
7
|
-
require 'protip/messages/currency'
|
8
|
-
require 'protip/messages/money'
|
9
|
-
require 'protip/messages/range'
|
10
|
-
require 'protip/messages/repeated_wrappers'
|
11
|
-
require 'protip/messages/types'
|
12
|
-
require 'protip/messages/wrappers'
|
13
|
-
require 'google/protobuf'
|
14
|
-
module Protip
|
15
|
-
class StandardConverter
|
16
|
-
include Protip::Converter
|
17
|
-
|
18
|
-
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON']
|
19
|
-
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF']
|
20
|
-
|
21
|
-
class << self
|
22
|
-
attr_reader :conversions
|
23
|
-
end
|
24
|
-
@conversions = {}
|
25
|
-
|
26
|
-
## Protip types
|
27
|
-
@conversions['protip.messages.Currency'] = {
|
28
|
-
to_object: ->(message, field) { message.currency_code },
|
29
|
-
to_message: ->(currency_code, message_class, field) { message_class.new currency_code: currency_code }
|
30
|
-
}
|
31
|
-
|
32
|
-
@conversions['protip.messages.Money'] = {
|
33
|
-
to_object: ->(message, field) do
|
34
|
-
::Money.new(message.amount_cents, message.currency.currency_code)
|
35
|
-
end,
|
36
|
-
to_message: ->(money, message_class, field) do
|
37
|
-
raise ArgumentError unless money.is_a?(::Money)
|
38
|
-
currency = ::Protip::Messages::Currency.new(currency_code: money.currency.iso_code.to_sym)
|
39
|
-
message_class.new(
|
40
|
-
amount_cents: money.fractional,
|
41
|
-
currency: currency
|
42
|
-
)
|
43
|
-
end
|
44
|
-
}
|
45
|
-
|
46
|
-
@conversions['protip.messages.Date'] = {
|
47
|
-
to_object: ->(message, field) { ::Date.new(message.year, message.month, message.day) },
|
48
|
-
to_message: lambda do |date, message_class, field|
|
49
|
-
raise ArgumentError unless date.is_a?(::Date)
|
50
|
-
message_class.new year: date.year, month: date.month, day: date.day
|
51
|
-
end
|
52
|
-
}
|
53
|
-
|
54
|
-
@conversions['protip.messages.Range'] = {
|
55
|
-
to_object: ->(message, field) { message.begin..message.end },
|
56
|
-
to_message: ->(range, message_class, field) do
|
57
|
-
message_class.new(begin: range.begin.to_i, end: range.end.to_i)
|
58
|
-
end
|
59
|
-
}
|
60
|
-
|
61
|
-
## Standard wrappers
|
62
|
-
{
|
63
|
-
Int64: :to_i,
|
64
|
-
Int32: :to_i,
|
65
|
-
UInt64: :to_i,
|
66
|
-
UInt32: :to_i,
|
67
|
-
Double: :to_f,
|
68
|
-
Float: :to_f,
|
69
|
-
String: :to_s,
|
70
|
-
Bytes: nil,
|
71
|
-
}.each do |type, conversion|
|
72
|
-
@conversions["google.protobuf.#{type}Value"] = {
|
73
|
-
to_object: ->(message, field) { message.value },
|
74
|
-
to_message: lambda do |value, message_class, field|
|
75
|
-
message_class.new value: (conversion ? value.public_send(conversion) : value)
|
76
|
-
end
|
77
|
-
}
|
78
|
-
@conversions["protip.messages.Repeated#{type}"] = {
|
79
|
-
to_object: ->(message, field) { message.values.to_a.freeze },
|
80
|
-
to_message: lambda do |value, message_class, field|
|
81
|
-
values = (value.is_a?(Enumerable) ? value : [value]).map do |v|
|
82
|
-
conversion ? v.public_send(conversion) : v
|
83
|
-
end
|
84
|
-
message_class.new values: values
|
85
|
-
end
|
86
|
-
}
|
87
|
-
end
|
88
|
-
|
89
|
-
conversions['google.protobuf.BoolValue'] = {
|
90
|
-
to_object: ->(message, field) { message.value },
|
91
|
-
to_message: lambda do |value, message_class, field|
|
92
|
-
message_class.new value: value_to_boolean(value)
|
93
|
-
end
|
94
|
-
}
|
95
|
-
|
96
|
-
conversions['protip.messages.RepeatedBool'] = {
|
97
|
-
to_object: ->(message, field) { message.values.to_a.freeze },
|
98
|
-
to_message: lambda do |value, message_class, field|
|
99
|
-
message_class.new values: (value.is_a?(Enumerable) ? value : [value]).map{|v| value_to_boolean(v)}
|
100
|
-
end
|
101
|
-
|
102
|
-
}
|
103
|
-
|
104
|
-
conversions['protip.messages.EnumValue'] = {
|
105
|
-
to_object: lambda do |message, field|
|
106
|
-
enum_for_field(field).lookup_value(message.value) || message.value
|
107
|
-
end,
|
108
|
-
to_message: lambda do |value, message_class, field|
|
109
|
-
enum_value = (value.is_a?(Fixnum) ? value : enum_for_field(field).lookup_name(value.to_sym))
|
110
|
-
if nil == enum_value
|
111
|
-
raise RangeError.new('Unknown symbol value for an EnumValue field.')
|
112
|
-
end
|
113
|
-
message_class.new(value: enum_value)
|
114
|
-
end
|
115
|
-
}
|
116
|
-
|
117
|
-
conversions['protip.messages.RepeatedEnum'] = {
|
118
|
-
to_object: lambda do |message, field|
|
119
|
-
enum = enum_for_field(field)
|
120
|
-
message.values.map{|v| enum.lookup_value(v) || v}
|
121
|
-
end,
|
122
|
-
to_message: lambda do |values, message_class, field|
|
123
|
-
enum = nil # Don't look this up unless we have to
|
124
|
-
(values = [values]) unless values.is_a?(Enumerable) # Convert to an array if a scalar was given
|
125
|
-
# Convert values in the same way we do for +protip.messages.EnumValue+
|
126
|
-
message_class.new values: (values.map do |value|
|
127
|
-
if value.is_a?(Fixnum)
|
128
|
-
value
|
129
|
-
else
|
130
|
-
enum ||= enum_for_field(field)
|
131
|
-
enum.lookup_name(value.to_sym) || (raise RangeError.new('Unknown symbol value for a RepeatedEnum field.'))
|
132
|
-
end
|
133
|
-
end)
|
134
|
-
end
|
135
|
-
}
|
136
|
-
|
137
|
-
## ActiveSupport objects
|
138
|
-
conversions['protip.messages.ActiveSupport.TimeWithZone'] = {
|
139
|
-
to_object: ->(message, field) {
|
140
|
-
ActiveSupport::TimeWithZone.new(
|
141
|
-
Time.at(message.utc_timestamp).utc,
|
142
|
-
ActiveSupport::TimeZone.new(message.time_zone_name)
|
143
|
-
)
|
144
|
-
},
|
145
|
-
to_message: ->(value, message_class, field) {
|
146
|
-
if !value.is_a?(::ActiveSupport::TimeWithZone) && (value.is_a?(Time) || value.is_a?(DateTime))
|
147
|
-
value = ::ActiveSupport::TimeWithZone.new(value.to_time.utc, ::ActiveSupport::TimeZone.new('UTC'))
|
148
|
-
end
|
149
|
-
raise ArgumentError unless value.is_a?(::ActiveSupport::TimeWithZone)
|
150
|
-
|
151
|
-
message_class.new(
|
152
|
-
utc_timestamp: value.to_i,
|
153
|
-
time_zone_name: value.time_zone.name,
|
154
|
-
)
|
155
|
-
}
|
156
|
-
}
|
157
|
-
|
158
|
-
def convertible?(message_class)
|
159
|
-
self.class.conversions.has_key?(message_class.descriptor.name)
|
160
|
-
end
|
161
|
-
|
162
|
-
def to_object(message, field)
|
163
|
-
self.class.conversions[message.class.descriptor.name][:to_object].call(message, field)
|
164
|
-
end
|
165
|
-
|
166
|
-
def to_message(object, message_class, field)
|
167
|
-
self.class.conversions[message_class.descriptor.name][:to_message].call(object, message_class, field)
|
168
|
-
end
|
169
|
-
|
170
|
-
class << self
|
171
|
-
# Similar to Rails 3 value_to_boolean
|
172
|
-
def value_to_boolean(value)
|
173
|
-
return true if TRUE_VALUES.include?(value)
|
174
|
-
return false if FALSE_VALUES.include?(value)
|
175
|
-
# If we don't get a truthy/falsey value, use the original value (which should raise an
|
176
|
-
# exception)
|
177
|
-
value
|
178
|
-
end
|
179
|
-
|
180
|
-
def enum_for_field(field)
|
181
|
-
Google::Protobuf::DescriptorPool.generated_pool.lookup(field.instance_variable_get(:'@_protip_enum_value'))
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|