usps-support 0.2.16 → 0.2.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bce8208e30970b38a32cbf63d9bdbffbb1fd2742f4437448558e836902f6b759
4
- data.tar.gz: 3979ae4877678e7e77b2d24f356779971c27ac45e15ae37224c1ca3c6320cd62
3
+ metadata.gz: f84d12114b2736b7ecfb613b69c163d32fc00b677d43bf8b496438ebee52f024
4
+ data.tar.gz: 2a44c47fa41a0e4f71d02c54c4470c12fc5e65bea7fa1f4a9f53f70711162bad
5
5
  SHA512:
6
- metadata.gz: f6ac28d7860b0cf34a219eecd31e9ef82b6c6486c319adebc279bf98489a97ef57892f41069945db8ed7145a4bc4995c66fcd2c86cf5b3d539d9f9c58d61aee8
7
- data.tar.gz: 80b016914233baac6712bf062d8719f24219dd335af850cee0a36fda5ce7af9b07b77bab3fa20f47f0801cc43fe0aafb5d3d748e0f77a45fb83290c82359944f
6
+ metadata.gz: df3da6f7a3518179d1314e689011ca67df3528d8eecfadde522809b6979cb9fb04b234bb4ba149dc384579214a239e2bfa5adb3297b95f587601ac41e7195263
7
+ data.tar.gz: 9c9fdb0fca89a714b7637ff2134272e53775af0a2fe904386bdaa9aecb2ac76537b65bba988f06d77b0578e3e402698a286062ced6c66bb9f5e8732c5ec615ed
data/Readme.md CHANGED
@@ -52,3 +52,17 @@ module Members
52
52
  end
53
53
  end
54
54
  ```
55
+
56
+ ### Protobuf Initializer
57
+
58
+ e.g. `config/initializers/protobuf.rb`
59
+
60
+ ```ruby
61
+ # Load all proto descriptors
62
+ Dir.glob('lib/proto/**/*.rb').each { |f| require_relative("../../#{f}") }
63
+
64
+ # Load all extensions, after descriptors, in file order
65
+ Dir.glob('lib/proto/extensions/*.rb').sort.each { |f| require_relative("../../#{f}") }
66
+
67
+ Usps::Example::SerializableMessage.extend(Usps::Support::Lib::ProtoSerialize)
68
+ ```
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Usps::Support::Lib
4
+ # Extension for protobuf message classes to support serializing models data
5
+ #
6
+ # Usage in model:
7
+ # serialize :proto, Proto::Message::Name
8
+ #
9
+ # Usage in extension config / initializer:
10
+ # Proto::Message::Name.extend(ProtoSerialize)
11
+ #
12
+ module ProtoSerialize
13
+ # Decode
14
+ def load(data)
15
+ data ? decode(data) : new
16
+ end
17
+
18
+ # Encode
19
+ def dump(data)
20
+ case data
21
+ when self
22
+ data.to_proto
23
+ when Hash
24
+ new(data).to_proto
25
+ when String
26
+ decode(data).to_proto # Decode/encode to validate
27
+ else
28
+ raise 'Unexpected data format'
29
+ end
30
+ end
31
+ end
32
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Support
5
- VERSION = '0.2.16'
5
+ VERSION = '0.2.17'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.16
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -70,6 +70,7 @@ files:
70
70
  - lib/usps/support/helpers/react_helper.rb
71
71
  - lib/usps/support/helpers/scss_helper.rb
72
72
  - lib/usps/support/lib.rb
73
+ - lib/usps/support/lib/proto_serialize.rb
73
74
  - lib/usps/support/lib/simple_cov.rb
74
75
  - lib/usps/support/lib/simple_cov/filters_parser.rb
75
76
  - lib/usps/support/lib/simple_cov/uncovered_lines_formatter.rb