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 +4 -4
- data/Readme.md +14 -0
- data/lib/usps/support/lib/proto_serialize.rb +32 -0
- data/lib/usps/support/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f84d12114b2736b7ecfb613b69c163d32fc00b677d43bf8b496438ebee52f024
|
|
4
|
+
data.tar.gz: 2a44c47fa41a0e4f71d02c54c4470c12fc5e65bea7fa1f4a9f53f70711162bad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
data/lib/usps/support/version.rb
CHANGED
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.
|
|
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
|