serdee 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/request_message.rb +2 -1
- data/examples/response_message.rb +2 -1
- data/examples/unified_message.rb +2 -1
- data/lib/serdee/attributes.rb +21 -14
- data/lib/serdee/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f831af6244168e3b41b10a9d8125de04f8aae255
|
4
|
+
data.tar.gz: 4c8880ec3892de9eb91b7ba40e8483e40bf76df5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc1e84c9985bde67bce5382f7c05ea7f8b216328c8b11207d66ff79028a54e9e44389f392579ef5234fa5d5b6315b96e3b38a9bc1096df51f3c034034cb2fc94
|
7
|
+
data.tar.gz: 06fd5fe404699eea0e0d4497f8bf3c3c856099bbbde09d32722ebf45ced15649226cb85da79bed5c3d63bdee6b3f3ea3b9abfab84f5bb01ca0057e94a956c7f3
|
data/examples/request_message.rb
CHANGED
@@ -3,7 +3,8 @@ require_relative "./unified_message"
|
|
3
3
|
require_relative "./response_code"
|
4
4
|
class ResponseMessage
|
5
5
|
include Serdee::Attributes
|
6
|
-
|
6
|
+
serialize_key { |key| key.camelize(:lower) }
|
7
|
+
deserialize_key { |key| key.underscore }
|
7
8
|
|
8
9
|
attr_accessor :request_id
|
9
10
|
|
data/examples/unified_message.rb
CHANGED
@@ -4,7 +4,8 @@ require_relative "./response_code"
|
|
4
4
|
|
5
5
|
class UnifiedMessage
|
6
6
|
include Serdee::Attributes
|
7
|
-
|
7
|
+
serialize_key { |key| key.camelize(:lower) }
|
8
|
+
deserialize_key { |key| key.underscore }
|
8
9
|
|
9
10
|
PROCESSING_CODES = {
|
10
11
|
balance_inquiry: "315400",
|
data/lib/serdee/attributes.rb
CHANGED
@@ -32,8 +32,8 @@ module Serdee
|
|
32
32
|
|
33
33
|
def as_json
|
34
34
|
self.class.insert_to(self, {}).deep_transform_keys! do |key|
|
35
|
-
if self.class.
|
36
|
-
self.class.
|
35
|
+
if self.class.serialize_key
|
36
|
+
self.class.serialize_key.call(key.to_s)
|
37
37
|
else
|
38
38
|
key.to_s
|
39
39
|
end
|
@@ -53,20 +53,23 @@ module Serdee
|
|
53
53
|
@serializers ||= {}
|
54
54
|
end
|
55
55
|
|
56
|
-
def
|
57
|
-
if
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
56
|
+
def serialize_key(method = nil, &block)
|
57
|
+
if method
|
58
|
+
@serialize_key = ->(key) { self.send(method, key) }
|
59
|
+
elsif block
|
60
|
+
@serialize_key = block
|
61
|
+
else
|
62
|
+
@serialize_key || Serdee.serialize_key
|
63
|
+
end
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
+
def deserialize_key(method = nil, &block)
|
67
|
+
if method
|
68
|
+
@deserialize_key = ->(key) { self.send(method, key) }
|
66
69
|
elsif block
|
67
|
-
@
|
70
|
+
@deserialize_key = block
|
68
71
|
else
|
69
|
-
|
72
|
+
@deserialize_key || Serdee.deserialize_key
|
70
73
|
end
|
71
74
|
end
|
72
75
|
|
@@ -106,7 +109,11 @@ module Serdee
|
|
106
109
|
def of_json(json)
|
107
110
|
allocate.tap do |obj|
|
108
111
|
data = json.deep_transform_keys do |key|
|
109
|
-
|
112
|
+
if deserialize_key
|
113
|
+
deserialize_key.call(key).to_sym
|
114
|
+
else
|
115
|
+
key.to_sym
|
116
|
+
end
|
110
117
|
end
|
111
118
|
extract_to(data, obj)
|
112
119
|
obj.deserialized_from = json
|
data/lib/serdee/version.rb
CHANGED