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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2055ac2380d914a39a6ab59358077cc0da0dfd316f5b3c319e44915d843c1ef
4
- data.tar.gz: 5bd188aa429d0e973b7de7a5b034a3fc1bd69eac1fc11672cc760c4cb588be63
3
+ metadata.gz: 94f544d61e8e65387846ec47aefbbe0fd42d35083a598f74e6e8e2647382173d
4
+ data.tar.gz: ee7af2cc6ff266ba8a3eaa6d31c55cec1dc4e3b8420d35520d74d7c2776af88d
5
5
  SHA512:
6
- metadata.gz: 03e7e719381b3a16ab8e5b4b98b5a172bfbfc39548ff99b348def412bb60272d3fb27fecfaca2f94fc860d1bfc0c351d111b591d3c8a783740ada189669e03f9
7
- data.tar.gz: 43ffbe1282ea2db17cdefcfedb4e46aceb828b441221c31cb9776dc4507ccfad34bf057b7ce13dd8154ce807f68361deb4a85d54037e23374538d911d9cf3092
6
+ metadata.gz: bb8e645231bc7fd06ab55906d75f854c33be32e8dcccc2bd47f3aa536deb205a493158cd7ba3d038f2149529933de369fd4a2de8a006e98702a73f2c226a1551
7
+ data.tar.gz: 9ccc08ff5ccd67954c0fb36598250488cf90f5ec09a8fd40145590e86509a73baa1fc35961c1217b3e5542530450596eaf7d4e66c04c3c0c125a06103a046e87
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: "2.5.0"
4
+ TargetRubyVersion: "2.7.0"
5
5
  Naming/FileName:
6
6
  Exclude:
7
7
  - 'benchmark/benchmark-serializer-json.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.0
data/.travis.yml CHANGED
@@ -3,5 +3,5 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 2.6.5
6
+ - 2.7.0
7
7
  before_install: gem install bundler -v 2.0.1
@@ -2,81 +2,81 @@
2
2
  ruby benchmark/benchmark-serializer-json.rb
3
3
 
4
4
  Rehearsal ------------------------------------------------
5
- as_json 0.298969 0.008275 0.307244 ( 0.307616)
6
- fast_jsonapi 0.232278 0.000439 0.232717 ( 0.232886)
7
- grape_entity 1.014712 0.001639 1.016351 ( 1.017073)
8
- blueprinter 0.342568 0.000333 0.342901 ( 0.343215)
9
- mutils 2.846847 3.318636 6.165483 ( 4.499497)
10
- roar 1.165221 0.021089 1.186310 ( 1.186998)
11
- panko 0.262190 0.005572 0.267762 ( 0.267947)
12
- --------------------------------------- total: 9.518768sec
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
- as_json 0.160771 0.000220 0.160991 ( 0.161083)
16
- fast_jsonapi 0.202366 0.000215 0.202581 ( 0.202866)
17
- grape_entity 0.908631 0.005240 0.913871 ( 0.914388)
18
- blueprinter 0.270655 0.000117 0.270772 ( 0.270940)
19
- mutils 2.629444 3.284792 5.914236 ( 4.256369)
20
- roar 1.006414 0.001231 1.007645 ( 1.008334)
21
- panko 0.169449 0.000395 0.169844 ( 0.170023)
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
- as_json 4.602 (± 3.1%) i/s - 46.000 in 10.084341s
33
- fast_jsonapi 3.7361.1%) i/s - 38.000 in 10.182740s
34
- grape_entity 0.983 (± 2.6%) i/s - 10.000 in 10.179913s
35
- blueprinter 3.0182.3%) i/s - 31.000 in 10.305027s
36
- mutils 0.2242.1%) i/s - 3.000 in 13.383544s
37
- roar 0.887 (± 2.1%) i/s - 9.000 in 10.166892s
38
- panko 4.874 (± 3.1%) i/s - 49.000 in 10.176593s
32
+ fast_jsonapi 2.5022.3%) i/s - 25.000 in 10.025595s
33
+ => mutils 3.0163.0%) i/s - 31.000 in 10.322736s
34
+ as_json 3.7663.2%) i/s - 38.000 in 10.197421s
35
+ grape_entity 0.5334.8%) i/s - 6.000 in 11.273301s
36
+ blueprinter 1.4973.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
- panko: 4.9 i/s
43
- as_json: 4.6 i/s - same-ish: difference falls within error
44
- fast_jsonapi: 3.7 i/s - 1.30x (± 0.04) slower
45
- blueprinter: 3.0 i/s - 1.61x (± 0.06) slower
46
- grape_entity: 1.0 i/s - 4.95x (± 0.20) slower
47
- roar: 0.9 i/s - 5.50x (± 0.20) slower
48
- mutils: 0.2 i/s - 21.74x (± 0.81) slower
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
- as_json 53.369M memsize ( 0.000 retained)
53
- 841.041k objects ( 0.000 retained)
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
- grape_entity 83.654M memsize ( 0.000 retained)
59
- 1.031M objects ( 0.000 retained)
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 31.341M memsize ( 0.000 retained)
62
- 280.327k objects ( 0.000 retained)
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 123.865M memsize ( 0.000 retained)
68
- 1.061M objects ( 0.000 retained)
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 53.374M memsize ( 0.000 retained)
71
- 841.114k objects ( 0.000 retained)
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
- blueprinter: 31340936 allocated
76
- fast_jsonapi: 33617288 allocated - 1.07x more
77
- as_json: 53369496 allocated - 1.70x more
78
- panko: 53374416 allocated - 1.70x more
79
- grape_entity: 83653952 allocated - 2.67x more
80
- roar: 123864600 allocated - 3.95x more
81
- mutils: 162078928 allocated - 5.17x more
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
- ## [v0.2.28](https://github.com/niteshpurohit/mutils/tree/v0.2.28) (2019-11-27)
3
- **Changes:**
4
- - Serializer scoped into mutils
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
- **Changes:**
12
- - Code smells fixed.
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mutils (0.2.31)
4
+ mutils (0.2.32)
5
5
  activesupport (>= 4.2)
6
6
 
7
7
  GEM
@@ -119,4 +119,4 @@ DEPENDENCIES
119
119
  rspec-xml_helpers
120
120
 
121
121
  BUNDLED WITH
122
- 2.0.2
122
+ 2.1.4
@@ -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(10_000) { |i| Issue.new(i, i, "Issue #{i}", users.sample, labels.sample(rand(2..4))) }
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
- name: :as_json,
187
- serializer: -> { issues.as_json },
188
- output_inspector: ->(output) { output.first }
189
- },
190
- {
191
- name: :fast_jsonapi,
192
- serializer: -> { FastJsonApi::IssueSerializer.new(issues, include: %i[labels user]).serializable_hash },
193
- output_inspector: ->(output) { output[:data].first }
194
- },
195
- {
196
- name: :grape_entity,
197
- serializer: -> { GrapeEntity::Issue.represent(issues).as_json },
198
- output_inspector: ->(output) { output.first }
199
- },
200
- {
201
- name: :blueprinter,
202
- serializer: -> { BluePrint::Issue.render_as_hash(issues) },
203
- output_inspector: ->(output) { output.first }
204
- },
205
- {
206
- name: :mutils,
207
- serializer: -> { Mutils::Issue.new(issues).as_json },
208
- output_inspector: ->(output) { output.first }
209
- },
210
- {
211
- name: :roar,
212
- serializer: -> { ROAR::IssueRepresenter.for_collection.new(issues).as_json },
213
- output_inspector: ->(output) { output.first }
214
- },
215
- {
216
- name: :panko,
217
- serializer: -> { Panko::ArraySerializer.new(issues, each_serializer: PANKO::IssueSerializer).as_json },
218
- output_inspector: ->(output) { output['subjects'].first }
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, :mutex
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 :method_to_serialize,
12
- :attributes_to_serialize,
13
- :serializer_name,
11
+ attr_accessor :serializer_name,
14
12
  :include_root,
15
- :array_index,
16
- :belongs_to_relationships,
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
- self.attributes_to_serialize = {} if attributes_to_serialize.nil?
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
- self.method_to_serialize = {} if method_to_serialize.nil?
23
- method_list&.each { |attr| method_to_serialize[attr] = attr }
21
+ parse_attributes_methods(method_list, 'method')
24
22
  end
25
23
 
26
- def belongs_to(relationship_name, options = {}, option_name = 'belongs_to')
27
- options = prepare_options(relationship_name, options, option_name)
28
- self.belongs_to_relationships = {} if belongs_to_relationships.nil?
29
- belongs_to_relationships[relationship_name] = options
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
- alias has_one belongs_to
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.has_many_relationships = {} if has_many_relationships.nil?
37
- has_many_relationships[relationship_name] = options
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
- relationships = [self.class.belongs_to_relationships, self.class.has_many_relationships]
23
- [fetch_attributes(self.class.attributes_to_serialize&.keys),
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(keys)
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
- invoke_send(hash, key, call_method)
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.compact.reduce(&:merge)
35
+ relationships = relationships_array&.compact
64
36
  hash = {}
65
- relationships&.keys&.each do |key|
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 = always_include.nil? ? false : always_include == true
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?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mutils
4
- VERSION = '0.2.31'
4
+ VERSION = '0.2.32'
5
5
  end
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.31
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.31
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: