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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2fe112ed6cdaf1cd66461af7dda6f655b2b818de5e3c53e9932e115daeefd77
4
- data.tar.gz: 8d54849329a8e725d7a1cb68df6650f3bec50dc40881728fb2dd703c16cd5cf0
3
+ metadata.gz: 27c5455f3a87cdcc93c46a8c715b18ade3a681f5c2cff42283e7b910f8ed7d1e
4
+ data.tar.gz: c7a3a754d887f00ec3652c3264f6c474ec30608148f392667cc7c1159524dff6
5
5
  SHA512:
6
- metadata.gz: 43c4b93e93306ccb4d59a6386576fe7277aa24306fa74a36b2661ca78671f0355a9b85ab085c32619117cfb3f1e57e8663e2873064bbfc8a6c12b7a9fa2aeb0a
7
- data.tar.gz: e843ff147fe2e66ebbcba2436ed372cbcce3b902282e8b71ce0b087ff8c16084cb2c74edd09fc9334040f6b0070c763479ba0f3dc38c0df177373fb2343441ed
6
+ metadata.gz: 99288e9f703d5b17535e1f989f7792e3de2dd93f1f9f313b62b13c6d72edecc47d358e4e8e973df8736fc642e8c27f1ffda6b9346ac587e70c0fdf94bb7018c4
7
+ data.tar.gz: fc9031c91ffaa474b3c339b9f7ee347d8a8c08dd3c820585d0882de169e31ff7c0ed27ded3b82584917ebd013804bdb49b6733ba938ea8c4aa176f7d65c182b5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fast_serializer_ruby (0.4.1)
4
+ fast_serializer_ruby (0.4.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -123,3 +123,6 @@ DEPENDENCIES
123
123
  rspec (~> 3.0)
124
124
  rspec-benchmark
125
125
  simplecov
126
+
127
+ BUNDLED WITH
128
+ 1.17.3
@@ -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 = nil
12
- @serialization_schema = JsonModel::Object.new
13
- @params = (params || {}).symbolize_keys
14
- @params[:self] = 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] = list.map(&:to_sym)
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] = list.map(&:to_sym)
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
- _serialization_schema = if is_collection
125
- JsonModel::Array.new(schema: serialization_schema)
126
- else
127
- serialization_schema
128
- end
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 = _serialization_schema.serialize(resource, _params_dup, context)
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastSerializer
4
- VERSION = '0.4.1'
4
+ VERSION = '0.4.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_serializer_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeny Stepanov