protip 0.15.0 → 0.16.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
  SHA1:
3
- metadata.gz: f2bcfe95ab05331d80a72680b824507b1183e50d
4
- data.tar.gz: d5bc2008b39cbc556793156b50d92dc455673860
3
+ metadata.gz: bfabbad582a0baed0a872fb8ffa205fe9bd3aeee
4
+ data.tar.gz: abd9f3a79716f0b5923172b16ed25cd7b888b7ca
5
5
  SHA512:
6
- metadata.gz: d5d2a3761f37f72cb7fef48d87195f286ad3da0ae7cd725c3a04c2fbf57fdff9ccde25f64a8eca5f9c36e85f3088cbd34d080d046ccd72da8ff7f96c47c66477
7
- data.tar.gz: 4b9f94b329d0c8f16c5ef2eba2b7a82dfbf5ae1d4bbdaf15c6a26f5cac24370b89d1dc4a5725003f9d22781306e7a8b5d47f396e3886d550a55d38a55b529360
6
+ metadata.gz: 97722deb1b3e9f6ae27e68df39a874fd7023eab4bb04da165fcfa8be35ad87403618f59b6a1ad33cd7d8fa0bca3e78ccf9952349d47976eda5b58ed59106d782
7
+ data.tar.gz: 796ef25a07172c55eb75259e809995d4e92003c9437e0ef2dbc3cc877aa811cca89ccfa470bf7f5ce9ff560ab70d30c5cbf365cd2238a91814425b1ad9b556e8
@@ -0,0 +1,182 @@
1
+ syntax = "proto3";
2
+
3
+ package protip.messages;
4
+
5
+ message Currency {
6
+ enum CurrencyCode {
7
+ AED = 0;
8
+ AFN = 1;
9
+ ALL = 2;
10
+ AMD = 3;
11
+ ANG = 4;
12
+ AOA = 5;
13
+ ARS = 6;
14
+ AUD = 7;
15
+ AWG = 8;
16
+ AZN = 9;
17
+ BAM = 10;
18
+ BBD = 11;
19
+ BDT = 12;
20
+ BGN = 13;
21
+ BHD = 14;
22
+ BIF = 15;
23
+ BMD = 16;
24
+ BND = 17;
25
+ BOB = 18;
26
+ BRL = 19;
27
+ BSD = 20;
28
+ BTN = 21;
29
+ BWP = 22;
30
+ BYR = 23;
31
+ BZD = 24;
32
+ CAD = 25;
33
+ CDF = 26;
34
+ CHF = 27;
35
+ CLF = 28;
36
+ CLP = 29;
37
+ CNY = 30;
38
+ COP = 31;
39
+ CRC = 32;
40
+ CUC = 33;
41
+ CUP = 34;
42
+ CVE = 35;
43
+ CZK = 36;
44
+ DJF = 37;
45
+ DKK = 38;
46
+ DOP = 39;
47
+ DZD = 40;
48
+ EGP = 41;
49
+ ERN = 42;
50
+ ETB = 43;
51
+ EUR = 44;
52
+ FJD = 45;
53
+ FKP = 46;
54
+ GBP = 47;
55
+ GEL = 48;
56
+ GHS = 49;
57
+ GIP = 50;
58
+ GMD = 51;
59
+ GNF = 52;
60
+ GTQ = 53;
61
+ GYD = 54;
62
+ HKD = 55;
63
+ HNL = 56;
64
+ HRK = 57;
65
+ HTG = 58;
66
+ HUF = 59;
67
+ IDR = 60;
68
+ ILS = 61;
69
+ INR = 62;
70
+ IQD = 63;
71
+ IRR = 64;
72
+ ISK = 65;
73
+ JMD = 66;
74
+ JOD = 67;
75
+ JPY = 68;
76
+ KES = 69;
77
+ KGS = 70;
78
+ KHR = 71;
79
+ KMF = 72;
80
+ KPW = 73;
81
+ KRW = 74;
82
+ KWD = 75;
83
+ KYD = 76;
84
+ KZT = 77;
85
+ LAK = 78;
86
+ LBP = 79;
87
+ LKR = 80;
88
+ LRD = 81;
89
+ LSL = 82;
90
+ LTL = 83;
91
+ LVL = 84;
92
+ LYD = 85;
93
+ MAD = 86;
94
+ MDL = 87;
95
+ MGA = 88;
96
+ MKD = 89;
97
+ MMK = 90;
98
+ MNT = 91;
99
+ MOP = 92;
100
+ MRO = 93;
101
+ MUR = 94;
102
+ MVR = 95;
103
+ MWK = 96;
104
+ MXN = 97;
105
+ MYR = 98;
106
+ MZN = 99;
107
+ NAD = 100;
108
+ NGN = 101;
109
+ NIO = 102;
110
+ NOK = 103;
111
+ NPR = 104;
112
+ NZD = 105;
113
+ OMR = 106;
114
+ PAB = 107;
115
+ PEN = 108;
116
+ PGK = 109;
117
+ PHP = 110;
118
+ PKR = 111;
119
+ PLN = 112;
120
+ PYG = 113;
121
+ QAR = 114;
122
+ RON = 115;
123
+ RSD = 116;
124
+ RUB = 117;
125
+ RWF = 118;
126
+ SAR = 119;
127
+ SBD = 120;
128
+ SCR = 121;
129
+ SDG = 122;
130
+ SEK = 123;
131
+ SGD = 124;
132
+ SHP = 125;
133
+ SKK = 126;
134
+ SLL = 127;
135
+ SOS = 128;
136
+ SRD = 129;
137
+ SSP = 130;
138
+ STD = 131;
139
+ SVC = 132;
140
+ SYP = 133;
141
+ SZL = 134;
142
+ THB = 135;
143
+ TJS = 136;
144
+ TMT = 137;
145
+ TND = 138;
146
+ TOP = 139;
147
+ TRY = 140;
148
+ TTD = 141;
149
+ TWD = 142;
150
+ TZS = 143;
151
+ UAH = 144;
152
+ UGX = 145;
153
+ USD = 146;
154
+ UYU = 147;
155
+ UZS = 148;
156
+ VEF = 149;
157
+ VND = 150;
158
+ VUV = 151;
159
+ WST = 152;
160
+ XAF = 153;
161
+ XAG = 154;
162
+ XAU = 155;
163
+ XCD = 156;
164
+ XDR = 157;
165
+ XOF = 158;
166
+ XPF = 159;
167
+ YER = 160;
168
+ ZAR = 161;
169
+ ZMK = 162;
170
+ ZMW = 163;
171
+ BTC = 164;
172
+ JEP = 165;
173
+ EEK = 166;
174
+ MTL = 167;
175
+ TMM = 168;
176
+ ZWD = 169;
177
+ ZWL = 170;
178
+ ZWN = 171;
179
+ ZWR = 172;
180
+ }
181
+ CurrencyCode currency_code = 1;
182
+ }
@@ -0,0 +1,10 @@
1
+ syntax = "proto3";
2
+
3
+ import "protip/messages/currency.proto";
4
+
5
+ package protip.messages;
6
+
7
+ message Money {
8
+ int64 amount_cents = 1;
9
+ Currency currency = 2;
10
+ }
@@ -0,0 +1,9 @@
1
+ syntax = "proto3";
2
+
3
+ package protip.messages;
4
+
5
+ // wraps a ruby range, e.g. (0..1)
6
+ message Range {
7
+ int64 begin = 1;
8
+ int64 end = 2;
9
+ }
@@ -0,0 +1,192 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: protip/messages/currency.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_message "protip.messages.Currency" do
8
+ optional :currency_code, :enum, 1, "protip.messages.Currency.CurrencyCode"
9
+ end
10
+ add_enum "protip.messages.Currency.CurrencyCode" do
11
+ value :AED, 0
12
+ value :AFN, 1
13
+ value :ALL, 2
14
+ value :AMD, 3
15
+ value :ANG, 4
16
+ value :AOA, 5
17
+ value :ARS, 6
18
+ value :AUD, 7
19
+ value :AWG, 8
20
+ value :AZN, 9
21
+ value :BAM, 10
22
+ value :BBD, 11
23
+ value :BDT, 12
24
+ value :BGN, 13
25
+ value :BHD, 14
26
+ value :BIF, 15
27
+ value :BMD, 16
28
+ value :BND, 17
29
+ value :BOB, 18
30
+ value :BRL, 19
31
+ value :BSD, 20
32
+ value :BTN, 21
33
+ value :BWP, 22
34
+ value :BYR, 23
35
+ value :BZD, 24
36
+ value :CAD, 25
37
+ value :CDF, 26
38
+ value :CHF, 27
39
+ value :CLF, 28
40
+ value :CLP, 29
41
+ value :CNY, 30
42
+ value :COP, 31
43
+ value :CRC, 32
44
+ value :CUC, 33
45
+ value :CUP, 34
46
+ value :CVE, 35
47
+ value :CZK, 36
48
+ value :DJF, 37
49
+ value :DKK, 38
50
+ value :DOP, 39
51
+ value :DZD, 40
52
+ value :EGP, 41
53
+ value :ERN, 42
54
+ value :ETB, 43
55
+ value :EUR, 44
56
+ value :FJD, 45
57
+ value :FKP, 46
58
+ value :GBP, 47
59
+ value :GEL, 48
60
+ value :GHS, 49
61
+ value :GIP, 50
62
+ value :GMD, 51
63
+ value :GNF, 52
64
+ value :GTQ, 53
65
+ value :GYD, 54
66
+ value :HKD, 55
67
+ value :HNL, 56
68
+ value :HRK, 57
69
+ value :HTG, 58
70
+ value :HUF, 59
71
+ value :IDR, 60
72
+ value :ILS, 61
73
+ value :INR, 62
74
+ value :IQD, 63
75
+ value :IRR, 64
76
+ value :ISK, 65
77
+ value :JMD, 66
78
+ value :JOD, 67
79
+ value :JPY, 68
80
+ value :KES, 69
81
+ value :KGS, 70
82
+ value :KHR, 71
83
+ value :KMF, 72
84
+ value :KPW, 73
85
+ value :KRW, 74
86
+ value :KWD, 75
87
+ value :KYD, 76
88
+ value :KZT, 77
89
+ value :LAK, 78
90
+ value :LBP, 79
91
+ value :LKR, 80
92
+ value :LRD, 81
93
+ value :LSL, 82
94
+ value :LTL, 83
95
+ value :LVL, 84
96
+ value :LYD, 85
97
+ value :MAD, 86
98
+ value :MDL, 87
99
+ value :MGA, 88
100
+ value :MKD, 89
101
+ value :MMK, 90
102
+ value :MNT, 91
103
+ value :MOP, 92
104
+ value :MRO, 93
105
+ value :MUR, 94
106
+ value :MVR, 95
107
+ value :MWK, 96
108
+ value :MXN, 97
109
+ value :MYR, 98
110
+ value :MZN, 99
111
+ value :NAD, 100
112
+ value :NGN, 101
113
+ value :NIO, 102
114
+ value :NOK, 103
115
+ value :NPR, 104
116
+ value :NZD, 105
117
+ value :OMR, 106
118
+ value :PAB, 107
119
+ value :PEN, 108
120
+ value :PGK, 109
121
+ value :PHP, 110
122
+ value :PKR, 111
123
+ value :PLN, 112
124
+ value :PYG, 113
125
+ value :QAR, 114
126
+ value :RON, 115
127
+ value :RSD, 116
128
+ value :RUB, 117
129
+ value :RWF, 118
130
+ value :SAR, 119
131
+ value :SBD, 120
132
+ value :SCR, 121
133
+ value :SDG, 122
134
+ value :SEK, 123
135
+ value :SGD, 124
136
+ value :SHP, 125
137
+ value :SKK, 126
138
+ value :SLL, 127
139
+ value :SOS, 128
140
+ value :SRD, 129
141
+ value :SSP, 130
142
+ value :STD, 131
143
+ value :SVC, 132
144
+ value :SYP, 133
145
+ value :SZL, 134
146
+ value :THB, 135
147
+ value :TJS, 136
148
+ value :TMT, 137
149
+ value :TND, 138
150
+ value :TOP, 139
151
+ value :TRY, 140
152
+ value :TTD, 141
153
+ value :TWD, 142
154
+ value :TZS, 143
155
+ value :UAH, 144
156
+ value :UGX, 145
157
+ value :USD, 146
158
+ value :UYU, 147
159
+ value :UZS, 148
160
+ value :VEF, 149
161
+ value :VND, 150
162
+ value :VUV, 151
163
+ value :WST, 152
164
+ value :XAF, 153
165
+ value :XAG, 154
166
+ value :XAU, 155
167
+ value :XCD, 156
168
+ value :XDR, 157
169
+ value :XOF, 158
170
+ value :XPF, 159
171
+ value :YER, 160
172
+ value :ZAR, 161
173
+ value :ZMK, 162
174
+ value :ZMW, 163
175
+ value :BTC, 164
176
+ value :JEP, 165
177
+ value :EEK, 166
178
+ value :MTL, 167
179
+ value :TMM, 168
180
+ value :ZWD, 169
181
+ value :ZWL, 170
182
+ value :ZWN, 171
183
+ value :ZWR, 172
184
+ end
185
+ end
186
+
187
+ module Protip
188
+ module Messages
189
+ Currency = Google::Protobuf::DescriptorPool.generated_pool.lookup("protip.messages.Currency").msgclass
190
+ Currency::CurrencyCode = Google::Protobuf::DescriptorPool.generated_pool.lookup("protip.messages.Currency.CurrencyCode").enummodule
191
+ end
192
+ end
@@ -0,0 +1,18 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: protip/messages/money.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'protip/messages/currency'
7
+ Google::Protobuf::DescriptorPool.generated_pool.build do
8
+ add_message "protip.messages.Money" do
9
+ optional :amount_cents, :int64, 1
10
+ optional :currency, :message, 2, "protip.messages.Currency"
11
+ end
12
+ end
13
+
14
+ module Protip
15
+ module Messages
16
+ Money = Google::Protobuf::DescriptorPool.generated_pool.lookup("protip.messages.Money").msgclass
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: protip/messages/range.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_message "protip.messages.Range" do
8
+ optional :begin, :int64, 1
9
+ optional :end, :int64, 2
10
+ end
11
+ end
12
+
13
+ module Protip
14
+ module Messages
15
+ Range = Google::Protobuf::DescriptorPool.generated_pool.lookup("protip.messages.Range").msgclass
16
+ end
17
+ end
@@ -1,5 +1,10 @@
1
+ require 'money'
2
+
1
3
  require 'protip/converter'
2
4
 
5
+ require 'protip/messages/currency'
6
+ require 'protip/messages/money'
7
+ require 'protip/messages/range'
3
8
  require 'protip/messages/types'
4
9
  require 'google/protobuf'
5
10
  module Protip
@@ -15,6 +20,25 @@ module Protip
15
20
  @conversions = {}
16
21
 
17
22
  ## Protip types
23
+ @conversions['protip.messages.Currency'] = {
24
+ to_object: ->(message) { message.currency_code },
25
+ to_message: ->(currency_code, message_class) { message_class.new currency_code: currency_code }
26
+ }
27
+
28
+ @conversions['protip.messages.Money'] = {
29
+ to_object: ->(message) do
30
+ ::Money.new(message.amount_cents, message.currency.currency_code)
31
+ end,
32
+ to_message: ->(money, message_class) do
33
+ raise ArgumentError unless money.is_a?(::Money)
34
+ currency = ::Protip::Messages::Currency.new(currency_code: money.currency.iso_code.to_sym)
35
+ message_class.new(
36
+ amount_cents: money.fractional,
37
+ currency: currency
38
+ )
39
+ end
40
+ }
41
+
18
42
  @conversions['protip.messages.Date'] = {
19
43
  to_object: ->(message) { ::Date.new(message.year, message.month, message.day) },
20
44
  to_message: lambda do |date, message_class|
@@ -23,6 +47,13 @@ module Protip
23
47
  end
24
48
  }
25
49
 
50
+ @conversions['protip.messages.Range'] = {
51
+ to_object: ->(message) { message.begin..message.end },
52
+ to_message: ->(range, message_class) do
53
+ message_class.new(begin: range.begin.to_i, end: range.end.to_i)
54
+ end
55
+ }
56
+
26
57
  ## Standard wrappers
27
58
  %w(Int64 Int32 UInt64 UInt32 Double Float String Bytes).map{|type| "google.protobuf.#{type}Value"}.each do |name|
28
59
  @conversions[name] = {
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require 'money'
2
3
 
3
4
  require 'google/protobuf/wrappers'
4
5
  require 'protip/standard_converter'
@@ -7,11 +8,19 @@ describe Protip::StandardConverter do
7
8
  let(:converter) { Protip::StandardConverter.new }
8
9
 
9
10
  let(:integer_types) do
10
- [Google::Protobuf::Int64Value, Google::Protobuf::Int32Value, Google::Protobuf::UInt64Value, Google::Protobuf::UInt32Value]
11
+ [
12
+ Google::Protobuf::Int64Value,
13
+ Google::Protobuf::Int32Value,
14
+ Google::Protobuf::UInt64Value,
15
+ Google::Protobuf::UInt32Value
16
+ ]
11
17
  end
12
18
 
13
19
  let(:float_types) do
14
- [Google::Protobuf::FloatValue, Google::Protobuf::DoubleValue]
20
+ [
21
+ Google::Protobuf::FloatValue,
22
+ Google::Protobuf::DoubleValue
23
+ ]
15
24
  end
16
25
 
17
26
  let(:bool_types) do
@@ -26,10 +35,18 @@ describe Protip::StandardConverter do
26
35
  [Google::Protobuf::BytesValue]
27
36
  end
28
37
 
38
+ let(:protip_types) do
39
+ [
40
+ Protip::Messages::Range,
41
+ Protip::Messages::Date,
42
+ Protip::Messages::Money,
43
+ Protip::Messages::Currency
44
+ ]
45
+ end
29
46
 
30
47
  describe '#convertible?' do
31
48
  it 'converts all standard types' do
32
- (integer_types + float_types + string_types + bool_types + [Protip::Messages::Date]).each do |message_class|
49
+ (integer_types + float_types + string_types + bool_types + protip_types).each do |message_class|
33
50
  assert converter.convertible?(message_class), "expected type #{message_class.descriptor.name} not convertible"
34
51
  end
35
52
  end
@@ -61,6 +78,27 @@ describe Protip::StandardConverter do
61
78
  assert_instance_of ::Date, date
62
79
  assert_equal '2015-02-09', date.strftime
63
80
  end
81
+
82
+ it 'converts ranges' do
83
+ range = converter.to_object(::Protip::Messages::Range.new begin: 1, end: 4)
84
+ assert_instance_of ::Range, range
85
+ assert_equal 1..4, range
86
+ end
87
+
88
+ it 'converts currency' do
89
+ currency = converter.to_object(::Protip::Messages::Currency.new currency_code: :GBP)
90
+ assert_equal :GBP, currency
91
+ end
92
+
93
+ it 'converts money' do
94
+ message = ::Protip::Messages::Money.new amount_cents: 250,
95
+ currency: (::Protip::Messages::Currency.new currency_code: :CAD)
96
+ money = converter.to_object(message)
97
+ assert_instance_of ::Money, money
98
+ assert_equal Money::Currency.new(:CAD), money.currency
99
+ assert_equal 250, money.fractional
100
+ assert_equal ::Money.new(250, 'CAD'), money
101
+ end
64
102
  end
65
103
 
66
104
  describe '#to_message' do
@@ -84,6 +122,29 @@ describe Protip::StandardConverter do
84
122
  assert_equal ::Protip::Messages::Date.new(year: 2012, month: 5, day: 7), converter.to_message(date, ::Protip::Messages::Date)
85
123
  end
86
124
 
125
+ it 'converts ranges' do
126
+ range = -1..34
127
+ assert_equal ::Protip::Messages::Range.new(begin: -1, end: 34), converter.to_message(range, ::Protip::Messages::Range)
128
+ end
129
+
130
+ it 'converts currency' do
131
+ currency = :HKD
132
+ message = converter.to_message(currency, ::Protip::Messages::Currency)
133
+ assert_equal ::Protip::Messages::Currency.new(currency_code: currency), message
134
+ end
135
+
136
+ it 'converts money' do
137
+ money = ::Money.new(250, 'CAD')
138
+ message = converter.to_message(money, ::Protip::Messages::Money)
139
+ assert_instance_of ::Protip::Messages::Money, message
140
+ assert_equal ::Protip::Messages::Money.new(
141
+ amount_cents: money.cents,
142
+ currency: ::Protip::Messages::Currency.new(
143
+ currency_code: money.currency.iso_code.to_sym
144
+ )),
145
+ message
146
+ end
147
+
87
148
  it 'converts truthy values to booleans' do
88
149
  [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].each do |truth_value|
89
150
  assert_equal Google::Protobuf::BoolValue.new(value: true),
@@ -105,6 +166,5 @@ describe Protip::StandardConverter do
105
166
  end
106
167
  end
107
168
  end
108
-
109
169
  end
110
170
  end
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.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AngelList
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-19 00:00:00.000000000 Z
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -64,6 +64,26 @@ dependencies:
64
64
  - - '='
65
65
  - !ruby/object:Gem::Version
66
66
  version: 3.0.0.alpha.4
67
+ - !ruby/object:Gem::Dependency
68
+ name: money
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 6.5.1
74
+ - - "<"
75
+ - !ruby/object:Gem::Version
76
+ version: '7.0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 6.5.1
84
+ - - "<"
85
+ - !ruby/object:Gem::Version
86
+ version: '7.0'
67
87
  - !ruby/object:Gem::Dependency
68
88
  name: minitest
69
89
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +166,10 @@ extra_rdoc_files: []
146
166
  files:
147
167
  - definitions/google/protobuf/wrappers.proto
148
168
  - definitions/protip/messages/array.proto
169
+ - definitions/protip/messages/currency.proto
149
170
  - definitions/protip/messages/errors.proto
171
+ - definitions/protip/messages/money.proto
172
+ - definitions/protip/messages/range.proto
150
173
  - definitions/protip/messages/types.proto
151
174
  - lib/google/protobuf/wrappers.rb
152
175
  - lib/protip.rb
@@ -154,7 +177,10 @@ files:
154
177
  - lib/protip/converter.rb
155
178
  - lib/protip/error.rb
156
179
  - lib/protip/messages/array.rb
180
+ - lib/protip/messages/currency.rb
157
181
  - lib/protip/messages/errors.rb
182
+ - lib/protip/messages/money.rb
183
+ - lib/protip/messages/range.rb
158
184
  - lib/protip/messages/types.rb
159
185
  - lib/protip/resource.rb
160
186
  - lib/protip/resource/creatable.rb