fast_serializer_ruby 0.2.1 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -3
- data/Gemfile.lock +1 -4
- data/lib/fast_serializer/json_model/attribute.rb +10 -1
- data/lib/fast_serializer/json_model/node.rb +1 -1
- data/lib/fast_serializer/json_model/relationship.rb +13 -3
- data/lib/fast_serializer/schema.rb +28 -7
- data/lib/fast_serializer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2fe112ed6cdaf1cd66461af7dda6f655b2b818de5e3c53e9932e115daeefd77
|
4
|
+
data.tar.gz: 8d54849329a8e725d7a1cb68df6650f3bec50dc40881728fb2dd703c16cd5cf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43c4b93e93306ccb4d59a6386576fe7277aa24306fa74a36b2661ca78671f0355a9b85ab085c32619117cfb3f1e57e8663e2873064bbfc8a6c12b7a9fa2aeb0a
|
7
|
+
data.tar.gz: e843ff147fe2e66ebbcba2436ed372cbcce3b902282e8b71ce0b087ff8c16084cb2c74edd09fc9334040f6b0070c763479ba0f3dc38c0df177373fb2343441ed
|
data/.travis.yml
CHANGED
@@ -17,9 +17,6 @@ matrix:
|
|
17
17
|
- rvm: ruby-head
|
18
18
|
- rvm: jruby-head
|
19
19
|
|
20
|
-
before_install:
|
21
|
-
- gem update --system -N
|
22
|
-
|
23
20
|
before_script:
|
24
21
|
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
25
22
|
- chmod +x ./cc-test-reporter
|
data/Gemfile.lock
CHANGED
@@ -24,7 +24,16 @@ module FastSerializer
|
|
24
24
|
|
25
25
|
cond = @opts[:if] || @opts[:unless]
|
26
26
|
|
27
|
-
res =
|
27
|
+
res = if cond.is_a?(Proc)
|
28
|
+
if cond.arity.abs == 1
|
29
|
+
context.instance_exec(resource, &cond)
|
30
|
+
else
|
31
|
+
context.instance_exec(resource, params, &cond)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
context.public_send(cond)
|
35
|
+
end
|
36
|
+
|
28
37
|
res = !res unless @opts[:unless].nil?
|
29
38
|
|
30
39
|
res
|
@@ -14,13 +14,23 @@ module FastSerializer
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def included?(resource, params, context)
|
17
|
-
super
|
17
|
+
super && include_relation?(params)
|
18
18
|
end
|
19
19
|
|
20
20
|
def include_relation?(params)
|
21
|
-
|
21
|
+
include?(params) && !exclude?(params)
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
+
def exclude?(params)
|
25
|
+
return false if params[:exclude].nil?
|
26
|
+
return false if params[:exclude].empty?
|
27
|
+
params[:exclude_index].key?(key)
|
28
|
+
end
|
29
|
+
|
30
|
+
def include?(params)
|
31
|
+
return true if params[:include].nil?
|
32
|
+
return false if params[:include].empty?
|
33
|
+
params[:include_index].has_key?(key)
|
24
34
|
end
|
25
35
|
end
|
26
36
|
end
|
@@ -12,11 +12,29 @@ module FastSerializer
|
|
12
12
|
@serialization_schema = JsonModel::Object.new
|
13
13
|
@params = (params || {}).symbolize_keys
|
14
14
|
@params[:self] = self
|
15
|
+
@params[:include_index] = {}
|
16
|
+
@params[:exclude_index] = {}
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
self.include = @params.delete(:include)
|
19
|
+
self.exclude = @params.delete(:exclude)
|
20
|
+
end
|
21
|
+
|
22
|
+
def include=(list)
|
23
|
+
return if !list
|
24
|
+
|
25
|
+
|
26
|
+
if list.any?
|
27
|
+
@params[:include] = list.map(&:to_sym)
|
28
|
+
@params[:include_index] = @params[:include].map { |key| [key, nil] }.to_h
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def exclude=(list)
|
33
|
+
return if !list
|
34
|
+
|
35
|
+
if list.any?
|
36
|
+
@params[:exclude] = list.map(&:to_sym)
|
37
|
+
@params[:exclude_index] = @params[:exclude].map { |key| [key, nil] }.to_h
|
20
38
|
end
|
21
39
|
end
|
22
40
|
|
@@ -101,6 +119,7 @@ module FastSerializer
|
|
101
119
|
meta = _params_dup.delete(:meta)
|
102
120
|
|
103
121
|
is_collection = resource.respond_to?(:size) && !resource.respond_to?(:each_pair)
|
122
|
+
is_collection = params.delete(:is_collection) if params.has_key?(:is_collection)
|
104
123
|
|
105
124
|
_serialization_schema = if is_collection
|
106
125
|
JsonModel::Array.new(schema: serialization_schema)
|
@@ -118,7 +137,7 @@ module FastSerializer
|
|
118
137
|
end
|
119
138
|
|
120
139
|
def serialize_resource_to_json(resource, params = {}, context = self)
|
121
|
-
FastSerializer.config.coder.dump(serialize_resource(resource, params))
|
140
|
+
FastSerializer.config.coder.dump(serialize_resource(resource, params, context))
|
122
141
|
end
|
123
142
|
|
124
143
|
module Mixin
|
@@ -147,11 +166,13 @@ module FastSerializer
|
|
147
166
|
self.params = params || {}
|
148
167
|
end
|
149
168
|
|
150
|
-
def serializable_hash
|
169
|
+
def serializable_hash(opts = {})
|
170
|
+
self.params = params.merge(opts)
|
151
171
|
self.class.__schema__.serialize_resource(resource, params, self)
|
152
172
|
end
|
153
173
|
|
154
|
-
def serialized_json
|
174
|
+
def serialized_json(opts = {})
|
175
|
+
self.params = params.merge(opts)
|
155
176
|
self.class.__schema__.serialize_resource_to_json(resource, params, self)
|
156
177
|
end
|
157
178
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_serializer_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeny Stepanov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|