mutils 0.2.31 → 0.2.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.ruby-version +1 -0
- data/.travis.yml +1 -1
- data/BENCHMARK-SERIALIZER-JSON.md +54 -54
- data/CHANGELOG.md +48 -12
- data/Gemfile.lock +2 -2
- data/benchmark/benchmark-serializer-json.rb +39 -37
- data/lib/mutils/serialization/base_serializer.rb +1 -2
- data/lib/mutils/serialization/serialization_includes.rb +3 -6
- data/lib/mutils/serialization/serialization_methods.rb +17 -13
- data/lib/mutils/serialization/serialization_results.rb +9 -43
- data/lib/mutils/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94f544d61e8e65387846ec47aefbbe0fd42d35083a598f74e6e8e2647382173d
|
4
|
+
data.tar.gz: ee7af2cc6ff266ba8a3eaa6d31c55cec1dc4e3b8420d35520d74d7c2776af88d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb8e645231bc7fd06ab55906d75f854c33be32e8dcccc2bd47f3aa536deb205a493158cd7ba3d038f2149529933de369fd4a2de8a006e98702a73f2c226a1551
|
7
|
+
data.tar.gz: 9ccc08ff5ccd67954c0fb36598250488cf90f5ec09a8fd40145590e86509a73baa1fc35961c1217b3e5542530450596eaf7d4e66c04c3c0c125a06103a046e87
|
data/.rubocop.yml
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.0
|
data/.travis.yml
CHANGED
@@ -2,81 +2,81 @@
|
|
2
2
|
ruby benchmark/benchmark-serializer-json.rb
|
3
3
|
|
4
4
|
Rehearsal ------------------------------------------------
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
roar 1.
|
11
|
-
panko 0.
|
12
|
-
--------------------------------------- total:
|
5
|
+
fast_jsonapi 0.420896 0.001788 0.422684 ( 0.425161)
|
6
|
+
=> mutils 0.330089 0.000778 0.330867 ( 0.331820)
|
7
|
+
as_json 0.328482 0.002571 0.331053 ( 0.333599)
|
8
|
+
grape_entity 2.136319 0.012292 2.148611 ( 2.160330)
|
9
|
+
blueprinter 0.809256 0.008755 0.818011 ( 0.826980)
|
10
|
+
roar 1.905847 0.019966 1.925813 ( 1.935937)
|
11
|
+
panko 0.323696 0.001208 0.324904 ( 0.325517)
|
12
|
+
--------------------------------------- total: 6.301943sec
|
13
13
|
|
14
14
|
user system total real
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
roar 1.
|
21
|
-
panko 0.
|
15
|
+
fast_jsonapi 0.329029 0.000763 0.329792 ( 0.330612)
|
16
|
+
=> mutils 0.255709 0.000688 0.256397 ( 0.257546)
|
17
|
+
as_json 0.259330 0.001016 0.260346 ( 0.261641)
|
18
|
+
grape_entity 1.653116 0.004544 1.657660 ( 1.659194)
|
19
|
+
blueprinter 0.692518 0.003879 0.696397 ( 0.700324)
|
20
|
+
roar 1.578995 0.011059 1.590054 ( 1.598151)
|
21
|
+
panko 0.270695 0.000999 0.271694 ( 0.272918)
|
22
22
|
|
23
23
|
Warming up --------------------------------------
|
24
|
-
as_json 1.000 i/100ms
|
25
24
|
fast_jsonapi 1.000 i/100ms
|
25
|
+
=> mutils 1.000 i/100ms
|
26
|
+
as_json 1.000 i/100ms
|
26
27
|
grape_entity 1.000 i/100ms
|
27
28
|
blueprinter 1.000 i/100ms
|
28
|
-
mutils 1.000 i/100ms
|
29
29
|
roar 1.000 i/100ms
|
30
30
|
panko 1.000 i/100ms
|
31
31
|
Calculating -------------------------------------
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
roar 0.
|
38
|
-
panko
|
32
|
+
fast_jsonapi 2.502 (± 2.3%) i/s - 25.000 in 10.025595s
|
33
|
+
=> mutils 3.016 (± 3.0%) i/s - 31.000 in 10.322736s
|
34
|
+
as_json 3.766 (± 3.2%) i/s - 38.000 in 10.197421s
|
35
|
+
grape_entity 0.533 (± 4.8%) i/s - 6.000 in 11.273301s
|
36
|
+
blueprinter 1.497 (± 3.8%) i/s - 15.000 in 10.095146s
|
37
|
+
roar 0.631 (± 2.2%) i/s - 7.000 in 11.087625s
|
38
|
+
panko 3.709 (± 3.0%) i/s - 37.000 in 10.073211s
|
39
39
|
with 95.0% confidence
|
40
40
|
|
41
41
|
Comparison:
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
roar: 0.
|
48
|
-
|
42
|
+
as_json: 3.8 i/s
|
43
|
+
panko: 3.7 i/s - same-ish: difference falls within error
|
44
|
+
=> mutils: 3.0 i/s - 1.25x (± 0.05) slower
|
45
|
+
fast_jsonapi: 2.5 i/s - 1.51x (± 0.06) slower
|
46
|
+
blueprinter: 1.5 i/s - 2.52x (± 0.13) slower
|
47
|
+
roar: 0.6 i/s - 5.96x (± 0.23) slower
|
48
|
+
grape_entity: 0.5 i/s - 7.06x (± 0.40) slower
|
49
49
|
with 95.0% confidence
|
50
50
|
|
51
51
|
Calculating -------------------------------------
|
52
|
-
|
53
|
-
|
54
|
-
8.000 strings ( 0.000 retained)
|
55
|
-
fast_jsonapi 33.617M memsize ( 0.000 retained)
|
56
|
-
490.404k objects ( 0.000 retained)
|
52
|
+
fast_jsonapi 62.915M memsize ( 0.000 retained)
|
53
|
+
980.599k objects ( 0.000 retained)
|
57
54
|
50.000 strings ( 0.000 retained)
|
58
|
-
|
59
|
-
1.
|
55
|
+
=> mutils 76.280M memsize ( 0.000 retained)
|
56
|
+
1.001M objects ( 0.000 retained)
|
57
|
+
6.000 strings ( 0.000 retained)
|
58
|
+
as_json 98.069M memsize ( 0.000 retained)
|
59
|
+
1.682M objects ( 0.000 retained)
|
60
|
+
8.000 strings ( 0.000 retained)
|
61
|
+
grape_entity 245.598M memsize ( 0.000 retained)
|
62
|
+
2.522M objects ( 0.000 retained)
|
60
63
|
4.000 strings ( 0.000 retained)
|
61
|
-
blueprinter
|
62
|
-
|
63
|
-
0.000 strings ( 0.000 retained)
|
64
|
-
mutils 162.079M memsize ( 0.000 retained)
|
65
|
-
1.282M objects ( 0.000 retained)
|
64
|
+
blueprinter 71.800M memsize ( 0.000 retained)
|
65
|
+
660.626k objects ( 0.000 retained)
|
66
66
|
0.000 strings ( 0.000 retained)
|
67
|
-
roar
|
68
|
-
1.
|
67
|
+
roar 220.796M memsize ( 0.000 retained)
|
68
|
+
1.822M objects ( 0.000 retained)
|
69
69
|
1.000 strings ( 0.000 retained)
|
70
|
-
panko
|
71
|
-
|
70
|
+
panko 98.073M memsize ( 0.000 retained)
|
71
|
+
1.682M objects ( 0.000 retained)
|
72
72
|
13.000 strings ( 0.000 retained)
|
73
73
|
|
74
74
|
Comparison:
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
roar:
|
81
|
-
|
75
|
+
fast_jsonapi: 62914944 allocated
|
76
|
+
blueprinter: 71800368 allocated - 1.14x more
|
77
|
+
=> mutils: 76279744 allocated - 1.21x more
|
78
|
+
as_json: 98068616 allocated - 1.56x more
|
79
|
+
panko: 98073200 allocated - 1.56x more
|
80
|
+
roar: 220795848 allocated - 3.51x more
|
81
|
+
grape_entity: 245598232 allocated - 3.90x more
|
82
82
|
```
|
data/CHANGELOG.md
CHANGED
@@ -1,27 +1,59 @@
|
|
1
1
|
# Changelog
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
|
3
|
+
## [v0.2.31](https://github.com/niteshpurohit/mutils/tree/v0.2.31) (2020-03-18)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/niteshpurohit/mutils/compare/v0.2.30...v0.2.31)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- Update version.rb [\#20](https://github.com/niteshpurohit/mutils/pull/20) ([niteshpurohit](https://github.com/niteshpurohit))
|
10
|
+
- Rake 13.0 [\#19](https://github.com/niteshpurohit/mutils/pull/19) ([niteshpurohit](https://github.com/niteshpurohit))
|
11
|
+
|
12
|
+
## [v0.2.30](https://github.com/niteshpurohit/mutils/tree/v0.2.30) (2020-03-17)
|
13
|
+
|
14
|
+
[Full Changelog](https://github.com/niteshpurohit/mutils/compare/v0.2.29...v0.2.30)
|
15
|
+
|
16
|
+
**Merged pull requests:**
|
17
|
+
|
18
|
+
- Deps [\#18](https://github.com/niteshpurohit/mutils/pull/18) ([niteshpurohit](https://github.com/niteshpurohit))
|
19
|
+
|
20
|
+
## [v0.2.29](https://github.com/niteshpurohit/mutils/tree/v0.2.29) (2019-12-07)
|
21
|
+
|
22
|
+
[Full Changelog](https://github.com/niteshpurohit/mutils/compare/v0.2.28...v0.2.29)
|
23
|
+
|
24
|
+
**Merged pull requests:**
|
25
|
+
|
26
|
+
- Scope Variable bug [\#14](https://github.com/niteshpurohit/mutils/pull/14) ([niteshpurohit](https://github.com/niteshpurohit))
|
27
|
+
|
28
|
+
## [v0.2.28](https://github.com/niteshpurohit/mutils/tree/v0.2.28) (2019-11-26)
|
5
29
|
|
6
30
|
[Full Changelog](https://github.com/niteshpurohit/mutils/compare/v0.2.27...v0.2.28)
|
7
31
|
|
32
|
+
**Implemented enhancements:**
|
33
|
+
|
34
|
+
- Feature/scoped generator [\#13](https://github.com/niteshpurohit/mutils/pull/13) ([niteshpurohit](https://github.com/niteshpurohit))
|
35
|
+
|
8
36
|
## [v0.2.27](https://github.com/niteshpurohit/mutils/tree/v0.2.27) (2019-11-25)
|
9
37
|
|
10
38
|
[Full Changelog](https://github.com/niteshpurohit/mutils/compare/v0.2.26...v0.2.27)
|
11
|
-
|
12
|
-
|
39
|
+
|
40
|
+
**Implemented enhancements:**
|
41
|
+
|
42
|
+
- feat: coveralls added [\#5](https://github.com/niteshpurohit/mutils/pull/5) ([niteshpurohit](https://github.com/niteshpurohit))
|
43
|
+
|
44
|
+
**Merged pull requests:**
|
45
|
+
|
46
|
+
- Update CHANGELOG.md [\#12](https://github.com/niteshpurohit/mutils/pull/12) ([niteshpurohit](https://github.com/niteshpurohit))
|
47
|
+
- Update version.rb [\#11](https://github.com/niteshpurohit/mutils/pull/11) ([niteshpurohit](https://github.com/niteshpurohit))
|
48
|
+
- Removing code smells [\#9](https://github.com/niteshpurohit/mutils/pull/9) ([niteshpurohit](https://github.com/niteshpurohit))
|
49
|
+
- Update README.md [\#8](https://github.com/niteshpurohit/mutils/pull/8) ([niteshpurohit](https://github.com/niteshpurohit))
|
50
|
+
- Update README.md [\#7](https://github.com/niteshpurohit/mutils/pull/7) ([niteshpurohit](https://github.com/niteshpurohit))
|
51
|
+
- Update README.md [\#6](https://github.com/niteshpurohit/mutils/pull/6) ([niteshpurohit](https://github.com/niteshpurohit))
|
13
52
|
|
14
53
|
## [v0.2.26](https://github.com/niteshpurohit/mutils/tree/v0.2.26) (2019-11-24)
|
15
54
|
|
16
55
|
[Full Changelog](https://github.com/niteshpurohit/mutils/compare/v0.2.25...v0.2.26)
|
17
56
|
|
18
|
-
**Changes:**
|
19
|
-
- Added xml serialization.
|
20
|
-
- rubocop offenses handled remaining added to todo.
|
21
|
-
- root added for json, now
|
22
|
-
- name_tag option added for Serializers to have custom name while serializing to json or xml
|
23
|
-
- added option name_tag, true for json serializing to generate json with root
|
24
|
-
|
25
57
|
## [v0.2.25](https://github.com/niteshpurohit/mutils/tree/v0.2.25) (2019-11-24)
|
26
58
|
|
27
59
|
[Full Changelog](https://github.com/niteshpurohit/mutils/compare/885f96959dd3701ac20ed0981b920be753c00db0...v0.2.25)
|
@@ -30,3 +62,7 @@
|
|
30
62
|
|
31
63
|
- Feature/improve concurrency [\#4](https://github.com/niteshpurohit/mutils/pull/4) ([niteshpurohit](https://github.com/niteshpurohit))
|
32
64
|
- Testing Deploy [\#3](https://github.com/niteshpurohit/mutils/pull/3) ([niteshpurohit](https://github.com/niteshpurohit))
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
data/Gemfile.lock
CHANGED
@@ -6,9 +6,11 @@ require_relative '../lib//mutils'
|
|
6
6
|
|
7
7
|
gemfile do
|
8
8
|
source 'https://rubygems.org'
|
9
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
9
10
|
gem 'oj'
|
10
11
|
gem 'benchmark-ips', require: 'benchmark/ips'
|
11
|
-
gem 'kalibera'
|
12
|
+
gem 'kalibera', :github => 'softdevteam/libkalibera', glob: 'ruby/*.gemspec'
|
13
|
+
# gem 'kalibera'
|
12
14
|
gem 'benchmark-memory', require: 'benchmark/memory'
|
13
15
|
|
14
16
|
gem 'activesupport'
|
@@ -179,44 +181,44 @@ end
|
|
179
181
|
# Generate data
|
180
182
|
users = Array.new(10) { |i| User.new(i, "User #{i}") }
|
181
183
|
labels = Array.new(4) { |i| Label.new(i, "Label #{i}", 'ffffff') }
|
182
|
-
issues = Array.new(
|
184
|
+
issues = Array.new(20_000) { |i| Issue.new(i, i, "Issue #{i}", users.sample, labels.sample(rand(2..4))) }
|
183
185
|
|
184
186
|
serializers = [
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
187
|
+
{
|
188
|
+
name: :fast_jsonapi,
|
189
|
+
serializer: -> { FastJsonApi::IssueSerializer.new(issues, include: %i[labels user]).serializable_hash },
|
190
|
+
output_inspector: ->(output) { output[:data].first }
|
191
|
+
},
|
192
|
+
{
|
193
|
+
name: :mutils,
|
194
|
+
serializer: -> { Mutils::Issue.new(issues).as_json },
|
195
|
+
output_inspector: ->(output) { output.first }
|
196
|
+
},
|
197
|
+
{
|
198
|
+
name: :as_json,
|
199
|
+
serializer: -> { issues.as_json },
|
200
|
+
output_inspector: ->(output) { output.first }
|
201
|
+
},
|
202
|
+
{
|
203
|
+
name: :grape_entity,
|
204
|
+
serializer: -> { GrapeEntity::Issue.represent(issues).as_json },
|
205
|
+
output_inspector: ->(output) { output.first }
|
206
|
+
},
|
207
|
+
{
|
208
|
+
name: :blueprinter,
|
209
|
+
serializer: -> { BluePrint::Issue.render_as_hash(issues) },
|
210
|
+
output_inspector: ->(output) { output.first }
|
211
|
+
},
|
212
|
+
{
|
213
|
+
name: :roar,
|
214
|
+
serializer: -> { ROAR::IssueRepresenter.for_collection.new(issues).as_json },
|
215
|
+
output_inspector: ->(output) { output.first }
|
216
|
+
},
|
217
|
+
{
|
218
|
+
name: :panko,
|
219
|
+
serializer: -> { Panko::ArraySerializer.new(issues, each_serializer: PANKO::IssueSerializer).as_json },
|
220
|
+
output_inspector: ->(output) { output['subjects'].first }
|
221
|
+
}
|
220
222
|
]
|
221
223
|
|
222
224
|
# Display output
|
@@ -15,7 +15,6 @@ module Mutils
|
|
15
15
|
options[:child] = false unless options[:child]
|
16
16
|
self.scope = object
|
17
17
|
self.options = options
|
18
|
-
self.mutex = Mutex.new
|
19
18
|
end
|
20
19
|
|
21
20
|
def as_json(_options = {})
|
@@ -45,7 +44,7 @@ module Mutils
|
|
45
44
|
private
|
46
45
|
|
47
46
|
attr_writer :scope
|
48
|
-
attr_accessor :options
|
47
|
+
attr_accessor :options
|
49
48
|
end
|
50
49
|
end
|
51
50
|
end
|
@@ -8,13 +8,10 @@ module Mutils
|
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
included do
|
10
10
|
class << self
|
11
|
-
attr_accessor :
|
12
|
-
:attributes_to_serialize,
|
13
|
-
:serializer_name,
|
11
|
+
attr_accessor :serializer_name,
|
14
12
|
:include_root,
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:has_many_relationships
|
13
|
+
:relationships,
|
14
|
+
:attributes_to_serialize
|
18
15
|
end
|
19
16
|
end
|
20
17
|
end
|
@@ -14,29 +14,31 @@ module Mutils
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def attributes(*attributes_list)
|
17
|
-
|
18
|
-
attributes_list&.each { |attr| attributes_to_serialize[attr] = attr }
|
17
|
+
parse_attributes_methods(attributes_list, 'attribute')
|
19
18
|
end
|
20
19
|
|
21
20
|
def custom_methods(*method_list)
|
22
|
-
|
23
|
-
method_list&.each { |attr| method_to_serialize[attr] = attr }
|
21
|
+
parse_attributes_methods(method_list, 'method')
|
24
22
|
end
|
25
23
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
def parse_attributes_methods(list, type)
|
25
|
+
self.attributes_to_serialize = {} if attributes_to_serialize.nil?
|
26
|
+
list&.each do |attr|
|
27
|
+
value = { method: type == 'method' }
|
28
|
+
attributes_to_serialize[attr] = value
|
29
|
+
end
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
def has_many(relationship_name, options = {}, option_name = 'has_many')
|
32
|
+
def relationship(relationship_name, options = {}, option_name = 'belongs_to')
|
35
33
|
options = prepare_options(relationship_name, options, option_name)
|
36
|
-
self.
|
37
|
-
|
34
|
+
self.relationships = {} if relationships.nil?
|
35
|
+
relationships[relationship_name] = options
|
38
36
|
end
|
39
37
|
|
38
|
+
alias belongs_to relationship
|
39
|
+
alias has_many relationship
|
40
|
+
alias has_one relationship
|
41
|
+
|
40
42
|
def prepare_options(relationship_name, options, option_name)
|
41
43
|
class_name = options[:serializer]
|
42
44
|
if class_name.nil?
|
@@ -47,6 +49,7 @@ module Mutils
|
|
47
49
|
raise "Serializer class not defined for relationship: #{relationship_name}" unless class_exists? class_name
|
48
50
|
|
49
51
|
options[:serializer] = class_name.to_s.constantize
|
52
|
+
options[:option_name] = option_name
|
50
53
|
options
|
51
54
|
end
|
52
55
|
|
@@ -54,6 +57,7 @@ module Mutils
|
|
54
57
|
klass = class_name.to_s.constantize rescue nil
|
55
58
|
klass && defined?(klass) && klass.is_a?(Class)
|
56
59
|
end
|
60
|
+
|
57
61
|
end
|
58
62
|
end
|
59
63
|
end
|
@@ -19,62 +19,28 @@ module Mutils
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def hashed_result
|
22
|
-
|
23
|
-
|
24
|
-
call_methods(self.class.method_to_serialize&.keys),
|
25
|
-
hash_relationships(relationships)].reduce(&:merge)
|
22
|
+
[fetch_attributes(self.class.attributes_to_serialize),
|
23
|
+
hash_relationships(self.class.relationships)].reduce(&:merge)
|
26
24
|
end
|
27
25
|
|
28
|
-
def fetch_attributes(
|
29
|
-
invoke_sends_async(keys)
|
30
|
-
end
|
31
|
-
|
32
|
-
def call_methods(keys)
|
33
|
-
invoke_sends(keys, true)
|
34
|
-
end
|
35
|
-
|
36
|
-
def invoke_sends(keys, call_method = nil)
|
26
|
+
def fetch_attributes(attributes)
|
37
27
|
hash = {}
|
38
|
-
keys&.each do |key|
|
39
|
-
|
28
|
+
attributes&.keys&.each do |key|
|
29
|
+
hash[key] = attributes[key.to_s.to_sym][:method] ? send(key) : scope.send(key)
|
40
30
|
end
|
41
31
|
hash
|
42
32
|
end
|
43
33
|
|
44
|
-
def invoke_sends_async(keys, call_method = nil)
|
45
|
-
hash = {}
|
46
|
-
runners = []
|
47
|
-
keys&.each do |key|
|
48
|
-
runners << Thread.new do
|
49
|
-
mutex.synchronize { invoke_send(hash, key, call_method) }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
runners.map(&:join)
|
53
|
-
hash
|
54
|
-
end
|
55
|
-
|
56
|
-
def invoke_send(hash, key, call_method = nil)
|
57
|
-
hash[key] = send(key) if call_method
|
58
|
-
hash[key] = scope.send(key) unless call_method
|
59
|
-
hash
|
60
|
-
end
|
61
|
-
|
62
34
|
def hash_relationships(relationships_array)
|
63
|
-
relationships = relationships_array
|
35
|
+
relationships = relationships_array&.compact
|
64
36
|
hash = {}
|
65
|
-
relationships&.keys&.each
|
66
|
-
if check_if_included(relationships, key)
|
67
|
-
klass = relationships[key][:serializer]
|
68
|
-
hash[key] = klass.new(scope.send(key)).to_h
|
69
|
-
end
|
70
|
-
end
|
37
|
+
relationships&.keys&.each { |key| check_if_included(relationships, key) && (hash[key] = relationships[key][:serializer].new(scope.send(key)).to_h) }
|
71
38
|
hash
|
72
39
|
end
|
73
40
|
|
74
41
|
def check_if_included(relationships, key)
|
75
|
-
always_include = relationships[key][:always_include]
|
76
|
-
always_include
|
77
|
-
always_include || (options[:includes]&.include?(key))
|
42
|
+
always_include = relationships[key][:always_include] == true
|
43
|
+
always_include || options[:includes]&.include?(key)
|
78
44
|
end
|
79
45
|
|
80
46
|
def scope_is_collection?
|
data/lib/mutils/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nitesh Purohit
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- ".rspec"
|
127
127
|
- ".rubocop.yml"
|
128
128
|
- ".rubocop_todo.yml"
|
129
|
+
- ".ruby-version"
|
129
130
|
- ".travis.yml"
|
130
131
|
- BENCHMARK-SERIALIZER-JSON.md
|
131
132
|
- CHANGELOG.md
|
@@ -154,7 +155,7 @@ licenses:
|
|
154
155
|
- MIT
|
155
156
|
metadata:
|
156
157
|
bug_tracker_uri: https://github.com/niteshpurohit/mutils/issues
|
157
|
-
source_code_uri: https://github.com/niteshpurohit/mutils/tree/v0.2.
|
158
|
+
source_code_uri: https://github.com/niteshpurohit/mutils/tree/v0.2.32
|
158
159
|
post_install_message:
|
159
160
|
rdoc_options: []
|
160
161
|
require_paths:
|