protip 0.30.2 → 0.30.3

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: 3d01442950fba3b19ad39bcdf586b9a014d826ac
4
- data.tar.gz: 42490671d547733c9fe1710ffeff2a14885c8b08
3
+ metadata.gz: 7767f62af66d64b4120e373355995027070a6278
4
+ data.tar.gz: 4b1e516325941982f8c619af5d7efc66a8c4b814
5
5
  SHA512:
6
- metadata.gz: bf03643eeee317c0949031d13d52b83649d1eff3a3f2454ff32d58b1988023a556a2b6c36060e0238c789e413132c05f3295bef119b4ed4face30524e489a4d3
7
- data.tar.gz: 1ed7c1ea9364614b06d45e081ee78ca9f2ba94d9b75e34a9fa880fc9600f64ab386e5b859c202bb1d7520f4a6d4c30c36dc64c07ee14034d61deaa1d3231e67d
6
+ metadata.gz: 767c87e9f58f602f06b25266d21327df7525b334a0abb310723ac42d4d4505113b30926ab2a087cf395240a384553620f7df033f5ebd0c2e39283bc118eddb35
7
+ data.tar.gz: 4a80c5588cc6fbb5b9ba466ee3da25ade548dcdab5329b388b0a92ff58546d4916a7fac2a2483542ae2d4a8b8d3e95fc70ebd330fc3803e24e77e8a80c04f43f
@@ -1,6 +1,7 @@
1
1
  syntax = "proto3";
2
2
 
3
3
  import public "protip/messages/array.proto";
4
+ import public "protip/messages/big_decimal_value.proto";
4
5
  import public "protip/messages/currency.proto";
5
6
  import public "protip/messages/errors.proto";
6
7
  import public "protip/messages/money.proto";
@@ -0,0 +1,7 @@
1
+ syntax = "proto3";
2
+
3
+ package protip.messages;
4
+
5
+ message BigDecimalValue {
6
+ bytes serialized = 1;
7
+ }
@@ -4,6 +4,7 @@
4
4
  require 'google/protobuf'
5
5
 
6
6
  require 'protip/messages/array'
7
+ require 'protip/messages/big_decimal_value'
7
8
  require 'protip/messages/currency'
8
9
  require 'protip/messages/errors'
9
10
  require 'protip/messages/money'
@@ -0,0 +1,16 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: protip/messages/big_decimal_value.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_message "protip.messages.BigDecimalValue" do
8
+ optional :serialized, :bytes, 1
9
+ end
10
+ end
11
+
12
+ module Protip
13
+ module Messages
14
+ BigDecimalValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("protip.messages.BigDecimalValue").msgclass
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ require 'bigdecimal'
2
+
3
+ require 'protip/transformer'
4
+ require 'protip/transformers/delegating_transformer'
5
+
6
+ module Protip
7
+ module Transformers
8
+ class BigDecimalTransformer < DelegatingTransformer
9
+ def initialize
10
+ super
11
+ self['protip.messages.BigDecimalValue'] = (Class.new do
12
+ include Protip::Transformer
13
+ def to_object(message, field)
14
+ BigDecimal._load(message.serialized)
15
+ end
16
+
17
+ def to_message(object, field)
18
+ field.subtype.msgclass.new(serialized: BigDecimal.new(object)._dump)
19
+ end
20
+ end).new
21
+ end
22
+ end
23
+ end
24
+ end
@@ -16,6 +16,7 @@ module Protip
16
16
  merge! Protip::Transformers::PrimitivesTransformer.new
17
17
  merge! Protip::Transformers::EnumTransformer.new
18
18
  merge! Protip::Transformers::DeprecatedTransformer.new
19
+ merge! Protip::Transformers::BigDecimalTransformer.new
19
20
  end
20
21
  end
21
22
  end
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+ require 'protip/transformers/big_decimal_transformer'
3
+
4
+ require 'protip/messages'
5
+
6
+ describe Protip::Transformers::BigDecimalTransformer do
7
+ let(:transformer) { Protip::Transformers::BigDecimalTransformer.new }
8
+ let(:message_class) { Protip::Messages::BigDecimalValue }
9
+ let(:field) do
10
+ field = mock.responds_like_instance_of ::Google::Protobuf::FieldDescriptor
11
+ field.stubs(:submsg_name).returns(message_class.descriptor.name)
12
+ field.stubs(:subtype).returns(message_class.descriptor)
13
+ field
14
+ end
15
+
16
+ # Since we're just serializing/deserializing values, we test both
17
+ # transformer methods in tandem.
18
+ describe 'transformation' do
19
+ def self.it_transforms(name, value)
20
+ it "transforms #{name} values" do
21
+ message = transformer.to_message(value, field)
22
+ assert_equal value, transformer.to_object(message, field)
23
+ end
24
+ end
25
+ it_transforms 'integer', BigDecimal.new(104, 1)
26
+ it_transforms 'infinity', (BigDecimal.new(1, 1) / 0)
27
+ it_transforms 'fractions', BigDecimal.new(100.5, 5)
28
+ it_transforms 'rational numbers', BigDecimal.new(Rational(2, 3), 3)
29
+ end
30
+ 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.30.2
4
+ version: 0.30.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - AngelList
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-03 00:00:00.000000000 Z
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -182,6 +182,7 @@ files:
182
182
  - definitions/protip/messages.proto
183
183
  - definitions/protip/messages/active_support/time_with_zone.proto
184
184
  - definitions/protip/messages/array.proto
185
+ - definitions/protip/messages/big_decimal_value.proto
185
186
  - definitions/protip/messages/currency.proto
186
187
  - definitions/protip/messages/errors.proto
187
188
  - definitions/protip/messages/money.proto
@@ -198,6 +199,7 @@ files:
198
199
  - lib/protip/messages.rb
199
200
  - lib/protip/messages/active_support/time_with_zone.rb
200
201
  - lib/protip/messages/array.rb
202
+ - lib/protip/messages/big_decimal_value.rb
201
203
  - lib/protip/messages/currency.rb
202
204
  - lib/protip/messages/errors.rb
203
205
  - lib/protip/messages/money.rb
@@ -219,6 +221,7 @@ files:
219
221
  - lib/protip/transformer.rb
220
222
  - lib/protip/transformers/abstract_transformer.rb
221
223
  - lib/protip/transformers/active_support/time_with_zone_transformer.rb
224
+ - lib/protip/transformers/big_decimal_transformer.rb
222
225
  - lib/protip/transformers/decorating_transformer.rb
223
226
  - lib/protip/transformers/default_transformer.rb
224
227
  - lib/protip/transformers/delegating_transformer.rb
@@ -234,6 +237,7 @@ files:
234
237
  - test/unit/protip/resource/associations/belongs_to_association_test.rb
235
238
  - test/unit/protip/resource/associations/belongs_to_polymorphic_association_test.rb
236
239
  - test/unit/protip/resource_test.rb
240
+ - test/unit/protip/transformers/big_decimal_transformer_test.rb
237
241
  - test/unit/protip/transformers/decorating_transformer_test.rb
238
242
  - test/unit/protip/transformers/delegating_transformer_test.rb
239
243
  - test/unit/protip/transformers/deprecated_transformer_test.rb