mutils 0.2.34 → 1.0.1
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/.github/CONTRIBUTING.md +3 -3
- data/.github/dependabot.yml +11 -0
- data/.gitignore +2 -0
- data/.huskyrc +7 -0
- data/.rspec +0 -1
- data/.rubocop.yml +2 -7
- data/.rubocop_todo.yml +13 -1
- data/.travis.yml +26 -4
- data/CHANGELOG.md +88 -37
- data/Gemfile +6 -0
- data/Gemfile.lock +44 -71
- data/README.md +118 -39
- data/SECURITY.md +13 -0
- data/Version +1 -0
- data/commitlint.config.js +1 -0
- data/gemdeploy.sh +10 -0
- data/lib/mutils.rb +3 -3
- data/lib/mutils/lib/helper.rb +42 -0
- data/lib/mutils/lib/result_hash.rb +25 -0
- data/lib/mutils/serialization/base_serializer.rb +0 -8
- data/lib/mutils/serialization/methods/attributes.rb +52 -0
- data/lib/mutils/serialization/methods/main.rb +27 -0
- data/lib/mutils/serialization/methods/relations.rb +40 -0
- data/lib/mutils/serialization/results/attributes.rb +24 -0
- data/lib/mutils/serialization/results/main.rb +59 -0
- data/lib/mutils/serialization/results/relations.rb +23 -0
- data/lib/mutils/serialization/serialization_includes.rb +9 -7
- data/lib/mutils/serialization/serialization_methods.rb +7 -67
- data/lib/mutils/serialization/serialization_results.rb +6 -57
- data/lib/mutils/version.rb +1 -1
- data/mutils.gemspec +5 -8
- data/package-lock.json +7157 -0
- data/package.json +94 -0
- metadata +25 -71
- data/.github/workflows/gempush.yml +0 -28
- data/.mergify.yml +0 -8
- data/.ruby-version +0 -1
- data/BENCHMARK-SERIALIZER-JSON.md +0 -82
- data/Makefile +0 -8
- data/benchmark/benchmark-serializer-json.rb +0 -252
data/package.json
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
{
|
2
|
+
"name": "mutils-dev",
|
3
|
+
"version": "0.0.0",
|
4
|
+
"description": "used to install husky and commit lint",
|
5
|
+
"main": "index.js",
|
6
|
+
"repository": "git@github.com:Code-Vedas/mutils.git",
|
7
|
+
"author": "Nitesh Purohit <nitesh.purohit.it@gmail.com>",
|
8
|
+
"license": "MIT",
|
9
|
+
"private": true,
|
10
|
+
"devDependencies": {
|
11
|
+
"@commitlint/cli": "^9.1.1",
|
12
|
+
"@commitlint/config-angular": "^9.1.1",
|
13
|
+
"@semantic-release/changelog": "^5.0.1",
|
14
|
+
"@semantic-release/exec": "^5.0.0",
|
15
|
+
"@semantic-release/git": "^9.0.0",
|
16
|
+
"@semantic-release/github": "^7.0.7",
|
17
|
+
"husky": "^4.2.5",
|
18
|
+
"lint-staged": "^10.2.11",
|
19
|
+
"semantic-release": "^17.1.1"
|
20
|
+
},
|
21
|
+
"scripts": {
|
22
|
+
"copyfiles": "cp -r CHANGELOG.md dist/CHANGELOG.md && cp -r dist/package.json src/package.json",
|
23
|
+
"semantic-release": "semantic-release"
|
24
|
+
},
|
25
|
+
"lint-staged": {
|
26
|
+
"*.{rb}": [
|
27
|
+
"bundle exec rubocop lib"
|
28
|
+
]
|
29
|
+
},
|
30
|
+
"husky": {
|
31
|
+
"hooks": {
|
32
|
+
"pre-commit": "lint-staged",
|
33
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
34
|
+
}
|
35
|
+
},
|
36
|
+
"release": {
|
37
|
+
"branch": "master",
|
38
|
+
"ci": false,
|
39
|
+
"verifyConditions": [
|
40
|
+
"@semantic-release/changelog",
|
41
|
+
"@semantic-release/git",
|
42
|
+
"@semantic-release/github"
|
43
|
+
],
|
44
|
+
"analyzeCommits": [
|
45
|
+
"@semantic-release/commit-analyzer"
|
46
|
+
],
|
47
|
+
"generateNotes": {
|
48
|
+
"path": "@semantic-release/release-notes-generator",
|
49
|
+
"preset": "angular",
|
50
|
+
"parserOpts": {
|
51
|
+
"noteKeywords": [
|
52
|
+
"BREAKING CHANGE",
|
53
|
+
"BREAKING CHANGES",
|
54
|
+
"BREAKING"
|
55
|
+
]
|
56
|
+
},
|
57
|
+
"writerOpts": {
|
58
|
+
"commitsSort": [
|
59
|
+
"scope",
|
60
|
+
"subject"
|
61
|
+
]
|
62
|
+
}
|
63
|
+
},
|
64
|
+
"prepare": [
|
65
|
+
{
|
66
|
+
"path": "@semantic-release/changelog",
|
67
|
+
"changelogFile": "CHANGELOG.md"
|
68
|
+
},
|
69
|
+
{
|
70
|
+
"path": "@semantic-release/exec",
|
71
|
+
"cmd": "echo \"v${nextRelease.version}\" > Version"
|
72
|
+
},
|
73
|
+
{
|
74
|
+
"path": "@semantic-release/exec",
|
75
|
+
"cmd": "echo \"Deploying Version: $(cat Version)\""
|
76
|
+
},
|
77
|
+
{
|
78
|
+
"path": "@semantic-release/exec",
|
79
|
+
"cmd": "./gemdeploy.sh"
|
80
|
+
},
|
81
|
+
{
|
82
|
+
"path": "@semantic-release/git",
|
83
|
+
"assets": [
|
84
|
+
"CHANGELOG.md",
|
85
|
+
"Version"
|
86
|
+
],
|
87
|
+
"message": "build(release): v${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
88
|
+
}
|
89
|
+
],
|
90
|
+
"publish": [
|
91
|
+
"@semantic-release/github"
|
92
|
+
]
|
93
|
+
}
|
94
|
+
}
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nitesh Purohit
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: dry-inflector
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: coveralls
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,48 +52,6 @@ dependencies:
|
|
66
52
|
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '13.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec-json_expectations
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec-rails
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rspec-xml_helpers
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
55
|
description: mutils Utilities for rails app
|
112
56
|
email:
|
113
57
|
- nitesh.purohit.it@gmail.com
|
@@ -121,42 +65,52 @@ files:
|
|
121
65
|
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
122
66
|
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
123
67
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
124
|
-
- ".github/
|
68
|
+
- ".github/dependabot.yml"
|
125
69
|
- ".gitignore"
|
126
|
-
- ".
|
70
|
+
- ".huskyrc"
|
127
71
|
- ".rspec"
|
128
72
|
- ".rubocop.yml"
|
129
73
|
- ".rubocop_todo.yml"
|
130
|
-
- ".ruby-version"
|
131
74
|
- ".travis.yml"
|
132
|
-
- BENCHMARK-SERIALIZER-JSON.md
|
133
75
|
- CHANGELOG.md
|
134
76
|
- CODE_OF_CONDUCT.md
|
135
77
|
- Gemfile
|
136
78
|
- Gemfile.lock
|
137
79
|
- LICENSE.txt
|
138
|
-
- Makefile
|
139
80
|
- README.md
|
140
81
|
- Rakefile
|
141
|
-
-
|
82
|
+
- SECURITY.md
|
83
|
+
- Version
|
142
84
|
- bin/console
|
143
85
|
- bin/setup
|
86
|
+
- commitlint.config.js
|
87
|
+
- gemdeploy.sh
|
144
88
|
- lib/generators/mutils/USAGE
|
145
89
|
- lib/generators/mutils/serializer_generator.rb
|
146
90
|
- lib/generators/mutils/templates/serializer.rb.tt
|
147
91
|
- lib/mutils.rb
|
92
|
+
- lib/mutils/lib/helper.rb
|
93
|
+
- lib/mutils/lib/result_hash.rb
|
148
94
|
- lib/mutils/serialization/base_serializer.rb
|
95
|
+
- lib/mutils/serialization/methods/attributes.rb
|
96
|
+
- lib/mutils/serialization/methods/main.rb
|
97
|
+
- lib/mutils/serialization/methods/relations.rb
|
98
|
+
- lib/mutils/serialization/results/attributes.rb
|
99
|
+
- lib/mutils/serialization/results/main.rb
|
100
|
+
- lib/mutils/serialization/results/relations.rb
|
149
101
|
- lib/mutils/serialization/serialization_includes.rb
|
150
102
|
- lib/mutils/serialization/serialization_methods.rb
|
151
103
|
- lib/mutils/serialization/serialization_results.rb
|
152
104
|
- lib/mutils/version.rb
|
153
105
|
- mutils.gemspec
|
154
|
-
|
106
|
+
- package-lock.json
|
107
|
+
- package.json
|
108
|
+
homepage: https://github.com/code-vedas/mutils
|
155
109
|
licenses:
|
156
110
|
- MIT
|
157
111
|
metadata:
|
158
|
-
bug_tracker_uri: https://github.com/
|
159
|
-
source_code_uri: https://github.com/
|
112
|
+
bug_tracker_uri: https://github.com/code-vedas/mutils/issues
|
113
|
+
source_code_uri: https://github.com/code-vedas/mutils/tree/v1.0.1
|
160
114
|
post_install_message:
|
161
115
|
rdoc_options: []
|
162
116
|
require_paths:
|
@@ -172,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
126
|
- !ruby/object:Gem::Version
|
173
127
|
version: 1.8.11
|
174
128
|
requirements: []
|
175
|
-
rubygems_version: 3.0.
|
129
|
+
rubygems_version: 3.0.8
|
176
130
|
signing_key:
|
177
131
|
specification_version: 4
|
178
132
|
summary: mutils Utilities for rails app
|
@@ -1,28 +0,0 @@
|
|
1
|
-
name: Ruby Gem
|
2
|
-
on:
|
3
|
-
release:
|
4
|
-
types: ["created"]
|
5
|
-
|
6
|
-
jobs:
|
7
|
-
build:
|
8
|
-
name: Build + Publish
|
9
|
-
runs-on: ubuntu-latest
|
10
|
-
|
11
|
-
steps:
|
12
|
-
- uses: actions/checkout@master
|
13
|
-
- name: Set up Ruby 2.6
|
14
|
-
uses: actions/setup-ruby@v1
|
15
|
-
with:
|
16
|
-
ruby-version: 2.6.x
|
17
|
-
|
18
|
-
- name: Publish to RubyGems
|
19
|
-
run: |
|
20
|
-
mkdir -p $HOME/.gem
|
21
|
-
touch $HOME/.gem/credentials
|
22
|
-
chmod 0600 $HOME/.gem/credentials
|
23
|
-
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
24
|
-
gem build *.gemspec
|
25
|
-
gem push *.gem
|
26
|
-
env:
|
27
|
-
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|
28
|
-
|
data/.mergify.yml
DELETED
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.7.0
|
@@ -1,82 +0,0 @@
|
|
1
|
-
```
|
2
|
-
ruby benchmark/benchmark-serializer-json.rb
|
3
|
-
|
4
|
-
Rehearsal ------------------------------------------------
|
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
|
-
|
14
|
-
user system total real
|
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
|
-
|
23
|
-
Warming up --------------------------------------
|
24
|
-
fast_jsonapi 1.000 i/100ms
|
25
|
-
=> mutils 1.000 i/100ms
|
26
|
-
as_json 1.000 i/100ms
|
27
|
-
grape_entity 1.000 i/100ms
|
28
|
-
blueprinter 1.000 i/100ms
|
29
|
-
roar 1.000 i/100ms
|
30
|
-
panko 1.000 i/100ms
|
31
|
-
Calculating -------------------------------------
|
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
|
-
with 95.0% confidence
|
40
|
-
|
41
|
-
Comparison:
|
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
|
-
with 95.0% confidence
|
50
|
-
|
51
|
-
Calculating -------------------------------------
|
52
|
-
fast_jsonapi 62.915M memsize ( 0.000 retained)
|
53
|
-
980.599k objects ( 0.000 retained)
|
54
|
-
50.000 strings ( 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)
|
63
|
-
4.000 strings ( 0.000 retained)
|
64
|
-
blueprinter 71.800M memsize ( 0.000 retained)
|
65
|
-
660.626k objects ( 0.000 retained)
|
66
|
-
0.000 strings ( 0.000 retained)
|
67
|
-
roar 220.796M memsize ( 0.000 retained)
|
68
|
-
1.822M objects ( 0.000 retained)
|
69
|
-
1.000 strings ( 0.000 retained)
|
70
|
-
panko 98.073M memsize ( 0.000 retained)
|
71
|
-
1.682M objects ( 0.000 retained)
|
72
|
-
13.000 strings ( 0.000 retained)
|
73
|
-
|
74
|
-
Comparison:
|
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
|
-
```
|
data/Makefile
DELETED
@@ -1,252 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/inline'
|
4
|
-
|
5
|
-
require_relative '../lib//mutils'
|
6
|
-
|
7
|
-
gemfile do
|
8
|
-
source 'https://rubygems.org'
|
9
|
-
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
10
|
-
gem 'oj'
|
11
|
-
gem 'benchmark-ips', require: 'benchmark/ips'
|
12
|
-
gem 'kalibera', :github => 'softdevteam/libkalibera', glob: 'ruby/*.gemspec'
|
13
|
-
# gem 'kalibera'
|
14
|
-
gem 'benchmark-memory', require: 'benchmark/memory'
|
15
|
-
|
16
|
-
gem 'activesupport'
|
17
|
-
|
18
|
-
# https://github.com/Netflix/fast_jsonapi
|
19
|
-
gem 'fast_jsonapi'
|
20
|
-
|
21
|
-
# https://github.com/ruby-grape/grape-entity
|
22
|
-
gem 'grape-entity'
|
23
|
-
|
24
|
-
# https://github.com/procore/blueprinter
|
25
|
-
gem 'blueprinter'
|
26
|
-
|
27
|
-
# https://github.com/trailblazer/roar
|
28
|
-
# https://github.com/trailblazer/representable
|
29
|
-
gem 'roar'
|
30
|
-
gem 'multi_json'
|
31
|
-
|
32
|
-
# https://github.com/yosiat/panko_serializer
|
33
|
-
gem 'panko_serializer'
|
34
|
-
end
|
35
|
-
|
36
|
-
require 'active_support'
|
37
|
-
require 'active_support/core_ext/object' # For Hash#deep_dup
|
38
|
-
|
39
|
-
# Define models
|
40
|
-
Issue = Struct.new(:id, :number, :title, :user, :labels) do
|
41
|
-
alias_method :read_attribute_for_serialization, :send
|
42
|
-
|
43
|
-
def label_ids
|
44
|
-
labels.map(&:id)
|
45
|
-
end
|
46
|
-
|
47
|
-
def user_id
|
48
|
-
user.id
|
49
|
-
end
|
50
|
-
end
|
51
|
-
User = Struct.new(:id, :login) do
|
52
|
-
alias_method :read_attribute_for_serialization, :send
|
53
|
-
end
|
54
|
-
Label = Struct.new(:id, :name, :color) do
|
55
|
-
alias_method :read_attribute_for_serialization, :send
|
56
|
-
end
|
57
|
-
|
58
|
-
# Define serializers
|
59
|
-
module FastJsonApi
|
60
|
-
class IssueSerializer
|
61
|
-
include FastJsonapi::ObjectSerializer
|
62
|
-
|
63
|
-
attributes :number, :title
|
64
|
-
has_many :labels
|
65
|
-
belongs_to :user
|
66
|
-
end
|
67
|
-
|
68
|
-
class LabelSerializer
|
69
|
-
include FastJsonapi::ObjectSerializer
|
70
|
-
|
71
|
-
attributes :name, :color
|
72
|
-
end
|
73
|
-
|
74
|
-
class UserSerializer
|
75
|
-
include FastJsonapi::ObjectSerializer
|
76
|
-
|
77
|
-
attributes :login
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
module GrapeEntity
|
82
|
-
class Label < Grape::Entity
|
83
|
-
expose :id
|
84
|
-
expose :name
|
85
|
-
expose :color
|
86
|
-
end
|
87
|
-
|
88
|
-
class User < Grape::Entity
|
89
|
-
expose :id
|
90
|
-
expose :login
|
91
|
-
end
|
92
|
-
|
93
|
-
class Issue < Grape::Entity
|
94
|
-
expose :id
|
95
|
-
expose :number
|
96
|
-
expose :title
|
97
|
-
expose :labels, using: Label
|
98
|
-
expose :user, using: User
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
Blueprinter.configure do |config|
|
103
|
-
config.generator = Oj
|
104
|
-
config.sort_fields_by = :definition
|
105
|
-
end
|
106
|
-
|
107
|
-
module BluePrint
|
108
|
-
class Label < Blueprinter::Base
|
109
|
-
identifier :id
|
110
|
-
fields :name, :color
|
111
|
-
end
|
112
|
-
|
113
|
-
class User < Blueprinter::Base
|
114
|
-
identifier :id
|
115
|
-
field :login
|
116
|
-
end
|
117
|
-
|
118
|
-
class Issue < Blueprinter::Base
|
119
|
-
identifier :id
|
120
|
-
fields :number, :title
|
121
|
-
association :labels, blueprint: Label
|
122
|
-
association :user, blueprint: User
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
module Mutils
|
127
|
-
class Label < Mutils::Serialization::BaseSerializer
|
128
|
-
attributes :id, :name, :color
|
129
|
-
end
|
130
|
-
|
131
|
-
class User < Mutils::Serialization::BaseSerializer
|
132
|
-
attributes :id, :login
|
133
|
-
end
|
134
|
-
|
135
|
-
class Issue < Mutils::Serialization::BaseSerializer
|
136
|
-
attributes :id, :number, :title
|
137
|
-
has_many :labels, serializer: Mutils::Label, always_include: true
|
138
|
-
belongs_to :user, serializer: Mutils::User, always_include: true
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
require 'roar/decorator'
|
143
|
-
require 'roar/json'
|
144
|
-
module ROAR
|
145
|
-
class IssueRepresenter < Roar::Decorator
|
146
|
-
include Roar::JSON
|
147
|
-
|
148
|
-
property :id
|
149
|
-
property :number
|
150
|
-
property :title
|
151
|
-
|
152
|
-
collection :labels do
|
153
|
-
property :id
|
154
|
-
property :name
|
155
|
-
property :color
|
156
|
-
end
|
157
|
-
|
158
|
-
property :user do
|
159
|
-
property :id
|
160
|
-
property :login
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
module PANKO
|
166
|
-
class LabelSerializer < Panko::Serializer
|
167
|
-
attributes :id, :name, :color
|
168
|
-
end
|
169
|
-
|
170
|
-
class UserSerializer < Panko::Serializer
|
171
|
-
attributes :id, :login
|
172
|
-
end
|
173
|
-
|
174
|
-
class IssueSerializer < Panko::Serializer
|
175
|
-
attributes :id, :number, :title
|
176
|
-
has_many :labels, serializer: LabelSerializer
|
177
|
-
has_one :user, serializer: UserSerializer
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
# Generate data
|
182
|
-
users = Array.new(10) { |i| User.new(i, "User #{i}") }
|
183
|
-
labels = Array.new(4) { |i| Label.new(i, "Label #{i}", 'ffffff') }
|
184
|
-
issues = Array.new(20_000) { |i| Issue.new(i, i, "Issue #{i}", users.sample, labels.sample(rand(2..4))) }
|
185
|
-
|
186
|
-
serializers = [
|
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
|
-
}
|
222
|
-
]
|
223
|
-
|
224
|
-
# Display output
|
225
|
-
serializers.each do |name:, serializer:, output_inspector:|
|
226
|
-
puts "\n#{name}:\n"
|
227
|
-
puts output_inspector.call(serializer.call).inspect
|
228
|
-
puts
|
229
|
-
end
|
230
|
-
|
231
|
-
# Run benchmarks
|
232
|
-
require 'benchmark'
|
233
|
-
Benchmark.bmbm do |b|
|
234
|
-
serializers.each do |name:, serializer:, **_other|
|
235
|
-
b.report(name, &serializer)
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
%i[ips memory].each do |bench|
|
240
|
-
puts '##################################################'
|
241
|
-
puts "START #{bench}"
|
242
|
-
puts '##################################################'
|
243
|
-
Benchmark.send(bench) do |b|
|
244
|
-
b.config(time: 10, warmup: 5, stats: :bootstrap, confidence: 95) if b.respond_to?(:config)
|
245
|
-
|
246
|
-
serializers.each do |name:, serializer:, **_other|
|
247
|
-
b.report(name, &serializer)
|
248
|
-
end
|
249
|
-
|
250
|
-
b.compare!
|
251
|
-
end
|
252
|
-
end
|