fast_serializer_ruby 0.4.1 → 0.4.2
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/Gemfile.lock +4 -1
- data/lib/fast_serializer/schema.rb +25 -14
- data/lib/fast_serializer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27c5455f3a87cdcc93c46a8c715b18ade3a681f5c2cff42283e7b910f8ed7d1e
|
4
|
+
data.tar.gz: c7a3a754d887f00ec3652c3264f6c474ec30608148f392667cc7c1159524dff6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99288e9f703d5b17535e1f989f7792e3de2dd93f1f9f313b62b13c6d72edecc47d358e4e8e973df8736fc642e8c27f1ffda6b9346ac587e70c0fdf94bb7018c4
|
7
|
+
data.tar.gz: fc9031c91ffaa474b3c339b9f7ee347d8a8c08dd3c820585d0882de169e31ff7c0ed27ded3b82584917ebd013804bdb49b6733ba938ea8c4aa176f7d65c182b5
|
data/Gemfile.lock
CHANGED
@@ -5,13 +5,15 @@ require 'forwardable'
|
|
5
5
|
module FastSerializer
|
6
6
|
|
7
7
|
class Schema
|
8
|
+
Context = Struct.new(:resource, :params)
|
9
|
+
|
8
10
|
attr_accessor :_root, :serialization_schema, :params
|
9
11
|
|
10
12
|
def initialize(params = {})
|
11
|
-
@root
|
12
|
-
@serialization_schema
|
13
|
-
@params
|
14
|
-
@params[:self]
|
13
|
+
@root = nil
|
14
|
+
@serialization_schema = JsonModel::Object.new
|
15
|
+
@params = (params || {}).symbolize_keys
|
16
|
+
@params[:self] = self
|
15
17
|
@params[:include_index] = {}
|
16
18
|
@params[:exclude_index] = {}
|
17
19
|
|
@@ -24,7 +26,7 @@ module FastSerializer
|
|
24
26
|
|
25
27
|
|
26
28
|
if list.any?
|
27
|
-
@params[:include]
|
29
|
+
@params[:include] = list.map(&:to_sym)
|
28
30
|
@params[:include_index] = @params[:include].map { |key| [key, nil] }.to_h
|
29
31
|
end
|
30
32
|
end
|
@@ -33,7 +35,7 @@ module FastSerializer
|
|
33
35
|
return if !list
|
34
36
|
|
35
37
|
if list.any?
|
36
|
-
@params[:exclude]
|
38
|
+
@params[:exclude] = list.map(&:to_sym)
|
37
39
|
@params[:exclude_index] = @params[:exclude].map { |key| [key, nil] }.to_h
|
38
40
|
end
|
39
41
|
end
|
@@ -121,15 +123,24 @@ module FastSerializer
|
|
121
123
|
is_collection = resource.respond_to?(:size) && !resource.respond_to?(:each_pair)
|
122
124
|
is_collection = params.delete(:is_collection) if params.has_key?(:is_collection)
|
123
125
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
126
|
+
root = (_root || _params_dup.delete(:root))
|
127
|
+
|
128
|
+
res = if is_collection
|
129
|
+
|
130
|
+
if !context.is_a?(self.class)
|
131
|
+
# need to bind context
|
132
|
+
resource.map { |entry| context.class.new(entry, _params_dup).serializable_hash }
|
133
|
+
else
|
134
|
+
JsonModel::Array.new(schema: serialization_schema).serialize(resource, _params_dup, context)
|
135
|
+
end
|
136
|
+
|
137
|
+
else
|
138
|
+
|
139
|
+
serialization_schema.serialize(resource, _params_dup, context)
|
140
|
+
|
141
|
+
end
|
129
142
|
|
130
|
-
res
|
131
|
-
root = (_root || _params_dup.delete(:root))
|
132
|
-
res = { root => res } if root && !root.empty?
|
143
|
+
res = { root => res } if root && !root.empty?
|
133
144
|
|
134
145
|
res[:meta] = meta if res.is_a?(Hash) && meta
|
135
146
|
|