mutils 0.2.36 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CONTRIBUTING.md +3 -3
- data/.github/dependabot.yml +10 -0
- data/.gitignore +1 -0
- data/.huskyrc +7 -0
- data/.rspec +0 -1
- data/.rubocop.yml +1 -2
- data/.rubocop_todo.yml +2 -0
- data/.travis.yml +18 -9
- data/CHANGELOG.md +93 -45
- data/Gemfile +6 -0
- data/Gemfile.lock +37 -1
- data/README.md +97 -35
- data/SECURITY.md +13 -0
- data/Version +1 -0
- data/commitlint.config.js +1 -0
- data/gemdeploy.sh +10 -0
- data/lib/mutils.rb +1 -0
- data/lib/mutils/lib/helper.rb +14 -4
- 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 +2 -1
- data/lib/mutils/serialization/serialization_methods.rb +6 -72
- data/lib/mutils/serialization/serialization_results.rb +6 -68
- data/lib/mutils/version.rb +1 -1
- data/mutils.gemspec +5 -7
- data/package-lock.json +7019 -0
- data/package.json +94 -0
- metadata +21 -52
- data/.github/workflows/gempush.yml +0 -28
- data/.mergify.yml +0 -8
- data/.ruby-version +0 -1
- data/Makefile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa28e1305e1235539317296db74c6b6509c5991c4cbacd731fe64bb70f1e32d3
|
4
|
+
data.tar.gz: ef7699f142663ee8a61d69c6f2059e657d35bb16606cf2d0486ec67a981da04d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bc5a5ee4df0ee503ff4e574a905dfd7309d30062bba0166e7f795d25378bd916cb2814494c00a64daa40ae1ccd8525031c6b155bb5f51f8f4a09157c45c5d77
|
7
|
+
data.tar.gz: e858cc6077fe7cb6cf14f2bd3dffe16acca0e974de7a0158f093a37bcfcf629d9a19f46a97656396b403e191b9d37d5140869b11f4dd32c7f9eaeb6e7ee0ab83
|
data/.github/CONTRIBUTING.md
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
We love pull requests from everyone. By participating in this project, you
|
4
4
|
agree to abide by the [code of conduct].
|
5
5
|
|
6
|
-
[code of conduct]: https://github.com/
|
6
|
+
[code of conduct]: https://github.com/code-vedas/mutils/blob/master/CODE_OF_CONDUCT.md
|
7
7
|
|
8
8
|
Fork, then clone the repo:
|
9
9
|
|
10
|
-
git clone git@github.com:
|
10
|
+
git clone git@github.com:code-vedas/mutils.git
|
11
11
|
|
12
12
|
Set up your machine:
|
13
13
|
|
@@ -23,7 +23,7 @@ Make your change. Add tests for your change. Make the tests pass:
|
|
23
23
|
|
24
24
|
Push to your fork and [submit a pull request][pr].
|
25
25
|
|
26
|
-
[pr]: https://github.com/
|
26
|
+
[pr]: https://github.com/code-vedas/mutils/compare/
|
27
27
|
|
28
28
|
At this point you're waiting on us. We like to at least comment on pull requests
|
29
29
|
within three business days (and, typically, one business day). We may suggest
|
data/.gitignore
CHANGED
data/.huskyrc
ADDED
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,20 +1,29 @@
|
|
1
|
-
os:
|
2
|
-
- linux
|
3
|
-
- osx
|
4
1
|
rvm:
|
5
2
|
- 2.5
|
6
3
|
- 2.6.3
|
7
4
|
- 2.6.5
|
8
5
|
- 2.7.0
|
9
6
|
- 2.7.1
|
10
|
-
- jruby-9.2
|
7
|
+
- jruby-9.2.5.0
|
8
|
+
- jruby-9.2.10.0
|
11
9
|
sudo: false
|
12
10
|
language: ruby
|
13
11
|
cache: bundler
|
14
|
-
before_install:
|
12
|
+
before_install:
|
13
|
+
- gem install bundler -v 2.0.1
|
14
|
+
- gem install rspec
|
15
|
+
- nvm use 11
|
16
|
+
- npm install
|
17
|
+
script: bundle exec rubocop lib && bundle exec rspec
|
15
18
|
branches:
|
16
19
|
only: master
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
bundler_args: --with=development,test --jobs=3 --retry=3
|
21
|
+
jobs:
|
22
|
+
include:
|
23
|
+
- stage: release
|
24
|
+
rvm: 2.6.5
|
25
|
+
script: npx semantic-release
|
26
|
+
stages:
|
27
|
+
- test
|
28
|
+
- name: release
|
29
|
+
if: (NOT type IN (pull_request)) AND (branch = master)
|
data/CHANGELOG.md
CHANGED
@@ -1,95 +1,143 @@
|
|
1
|
-
|
1
|
+
## [1.1.1](https://github.com/Code-Vedas/mutils/compare/v1.1.0...v1.1.1) (2020-10-05)
|
2
2
|
|
3
|
-
## [v0.2.34](https://github.com/niteshpurohit/mutils/tree/v0.2.34) (2020-03-29)
|
4
3
|
|
5
|
-
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* **params:** always send hash in params ([7d71b6d](https://github.com/Code-Vedas/mutils/commit/7d71b6d2c89f39883745a40e5472c444b5673e8b))
|
7
|
+
|
8
|
+
# [1.1.0](https://github.com/Code-Vedas/mutils/compare/v1.0.1...v1.1.0) (2020-08-15)
|
9
|
+
|
10
|
+
|
11
|
+
### Features
|
12
|
+
|
13
|
+
* **params:** conditional if:Proc get params as second attribute ([55a3b08](https://github.com/Code-Vedas/mutils/commit/55a3b08fee52c0dbef2b22c6e4f468389f8c53a4))
|
14
|
+
|
15
|
+
## [1.0.1](https://github.com/Code-Vedas/mutils/compare/v1.0.0...v1.0.1) (2020-07-24)
|
6
16
|
|
7
|
-
**Merged pull requests:**
|
8
17
|
|
9
|
-
|
18
|
+
### Bug Fixes
|
10
19
|
|
11
|
-
|
20
|
+
* **semantic-release:** enable semantic-release ([aa9c28f](https://github.com/Code-Vedas/mutils/commit/aa9c28fb8da7fcd1915a189bda22f8421a566eee))
|
12
21
|
|
13
|
-
[
|
22
|
+
## [1.0.0](https://github.com/code-vedas/mutils/tree/v0.2.36) (2020-04-17)
|
23
|
+
|
24
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.36...v1.0.0)
|
25
|
+
|
26
|
+
**First Stable release: Features**
|
27
|
+
- Performance upto 35i/s under load
|
28
|
+
- Observed 35-40 MB of memory usage
|
29
|
+
- Fully featured JSON serializer similar to Active Serializer but with more power and speed.
|
30
|
+
|
31
|
+
**Changes:**
|
32
|
+
- Code refactored
|
33
|
+
- Using cache for expensive operations
|
34
|
+
|
35
|
+
## [0.2.36](https://github.com/code-vedas/mutils/tree/v0.2.36) (2020-04-14)
|
36
|
+
|
37
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.35...v0.2.36)
|
14
38
|
|
15
39
|
**Merged pull requests:**
|
16
40
|
|
17
|
-
-
|
18
|
-
-
|
19
|
-
-
|
20
|
-
- changelog: v0.2.32 [\#22](https://github.com/niteshpurohit/mutils/pull/22) ([niteshpurohit](https://github.com/niteshpurohit))
|
41
|
+
- Remove active support dep [\#34](https://github.com/code-vedas/mutils/pull/34) ([niteshpurohit](https://github.com/niteshpurohit))
|
42
|
+
- Conditional attributes and relations [\#32](https://github.com/code-vedas/mutils/pull/32) ([niteshpurohit](https://github.com/niteshpurohit))
|
43
|
+
- chore: add more ruby version and os to test [\#31](https://github.com/code-vedas/mutils/pull/31) ([niteshpurohit](https://github.com/niteshpurohit))
|
21
44
|
|
22
|
-
## [
|
45
|
+
## [0.2.35](https://github.com/code-vedas/mutils/tree/v0.2.35) (2020-03-30)
|
23
46
|
|
24
|
-
[Full Changelog](https://github.com/
|
47
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.34...v0.2.35)
|
25
48
|
|
26
49
|
**Merged pull requests:**
|
27
50
|
|
28
|
-
-
|
51
|
+
- new option 'label' for relations [\#30](https://github.com/code-vedas/mutils/pull/30) ([niteshpurohit](https://github.com/niteshpurohit))
|
52
|
+
- added custom\_method and attribute example [\#29](https://github.com/code-vedas/mutils/pull/29) ([niteshpurohit](https://github.com/niteshpurohit))
|
53
|
+
- chore: update changelog [\#28](https://github.com/code-vedas/mutils/pull/28) ([niteshpurohit](https://github.com/niteshpurohit))
|
29
54
|
|
30
|
-
## [
|
55
|
+
## [0.2.34](https://github.com/code-vedas/mutils/tree/v0.2.34) (2020-03-29)
|
31
56
|
|
32
|
-
[Full Changelog](https://github.com/
|
57
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.33...v0.2.34)
|
33
58
|
|
34
59
|
**Merged pull requests:**
|
35
60
|
|
36
|
-
-
|
37
|
-
- Rake 13.0 [\#19](https://github.com/niteshpurohit/mutils/pull/19) ([niteshpurohit](https://github.com/niteshpurohit))
|
61
|
+
- Feature/attribute can be optional [\#27](https://github.com/code-vedas/mutils/pull/27) ([niteshpurohit](https://github.com/niteshpurohit))
|
38
62
|
|
39
|
-
## [
|
63
|
+
## [0.2.33](https://github.com/code-vedas/mutils/tree/v0.2.33) (2020-03-29)
|
40
64
|
|
41
|
-
[Full Changelog](https://github.com/
|
65
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.32...v0.2.33)
|
42
66
|
|
43
67
|
**Merged pull requests:**
|
44
68
|
|
45
|
-
-
|
69
|
+
- Added new custom\_method in serializer to control if include method [\#26](https://github.com/code-vedas/mutils/pull/26) ([niteshpurohit](https://github.com/niteshpurohit))
|
70
|
+
- Update CHANGELOG.md [\#25](https://github.com/code-vedas/mutils/pull/25) ([niteshpurohit](https://github.com/niteshpurohit))
|
71
|
+
- Create .codeclimate.yml [\#24](https://github.com/code-vedas/mutils/pull/24) ([niteshpurohit](https://github.com/niteshpurohit))
|
72
|
+
- changelog: v0.2.32 [\#22](https://github.com/code-vedas/mutils/pull/22) ([niteshpurohit](https://github.com/niteshpurohit))
|
46
73
|
|
47
|
-
## [
|
74
|
+
## [0.2.32](https://github.com/code-vedas/mutils/tree/v0.2.32) (2020-03-18)
|
48
75
|
|
49
|
-
[Full Changelog](https://github.com/
|
76
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.31...v0.2.32)
|
50
77
|
|
51
78
|
**Merged pull requests:**
|
52
79
|
|
53
|
-
-
|
80
|
+
- Feature/improve performance [\#21](https://github.com/code-vedas/mutils/pull/21) ([niteshpurohit](https://github.com/niteshpurohit))
|
54
81
|
|
55
|
-
## [
|
82
|
+
## [0.2.31](https://github.com/code-vedas/mutils/tree/v0.2.31) (2020-03-18)
|
56
83
|
|
57
|
-
[Full Changelog](https://github.com/
|
84
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.30...v0.2.31)
|
58
85
|
|
59
|
-
**
|
86
|
+
**Merged pull requests:**
|
60
87
|
|
61
|
-
-
|
88
|
+
- Update version.rb [\#20](https://github.com/code-vedas/mutils/pull/20) ([niteshpurohit](https://github.com/niteshpurohit))
|
89
|
+
- Rake 13.0 [\#19](https://github.com/code-vedas/mutils/pull/19) ([niteshpurohit](https://github.com/niteshpurohit))
|
62
90
|
|
63
|
-
## [
|
91
|
+
## [0.2.30](https://github.com/code-vedas/mutils/tree/v0.2.30) (2020-03-17)
|
64
92
|
|
65
|
-
[Full Changelog](https://github.com/
|
93
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.29...v0.2.30)
|
66
94
|
|
67
|
-
**
|
95
|
+
**Merged pull requests:**
|
96
|
+
|
97
|
+
- Deps [\#18](https://github.com/code-vedas/mutils/pull/18) ([niteshpurohit](https://github.com/niteshpurohit))
|
68
98
|
|
69
|
-
|
99
|
+
## [0.2.29](https://github.com/code-vedas/mutils/tree/v0.2.29) (2019-12-07)
|
100
|
+
|
101
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.28...v0.2.29)
|
70
102
|
|
71
103
|
**Merged pull requests:**
|
72
104
|
|
73
|
-
-
|
74
|
-
- Update version.rb [\#11](https://github.com/niteshpurohit/mutils/pull/11) ([niteshpurohit](https://github.com/niteshpurohit))
|
75
|
-
- Removing code smells [\#9](https://github.com/niteshpurohit/mutils/pull/9) ([niteshpurohit](https://github.com/niteshpurohit))
|
76
|
-
- Update README.md [\#8](https://github.com/niteshpurohit/mutils/pull/8) ([niteshpurohit](https://github.com/niteshpurohit))
|
77
|
-
- Update README.md [\#7](https://github.com/niteshpurohit/mutils/pull/7) ([niteshpurohit](https://github.com/niteshpurohit))
|
78
|
-
- Update README.md [\#6](https://github.com/niteshpurohit/mutils/pull/6) ([niteshpurohit](https://github.com/niteshpurohit))
|
105
|
+
- Scope Variable bug [\#14](https://github.com/code-vedas/mutils/pull/14) ([niteshpurohit](https://github.com/niteshpurohit))
|
79
106
|
|
80
|
-
## [
|
107
|
+
## [0.2.28](https://github.com/code-vedas/mutils/tree/v0.2.28) (2019-11-26)
|
81
108
|
|
82
|
-
[Full Changelog](https://github.com/
|
109
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.27...v0.2.28)
|
83
110
|
|
84
|
-
|
111
|
+
**Implemented enhancements:**
|
85
112
|
|
86
|
-
[
|
113
|
+
- Feature/scoped generator [\#13](https://github.com/code-vedas/mutils/pull/13) ([niteshpurohit](https://github.com/niteshpurohit))
|
114
|
+
|
115
|
+
## [0.2.27](https://github.com/code-vedas/mutils/tree/v0.2.27) (2019-11-25)
|
116
|
+
|
117
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.26...v0.2.27)
|
118
|
+
|
119
|
+
**Implemented enhancements:**
|
120
|
+
|
121
|
+
- feat: coveralls added [\#5](https://github.com/code-vedas/mutils/pull/5) ([niteshpurohit](https://github.com/niteshpurohit))
|
87
122
|
|
88
123
|
**Merged pull requests:**
|
89
124
|
|
90
|
-
-
|
91
|
-
-
|
125
|
+
- Update CHANGELOG.md [\#12](https://github.com/code-vedas/mutils/pull/12) ([niteshpurohit](https://github.com/niteshpurohit))
|
126
|
+
- Update version.rb [\#11](https://github.com/code-vedas/mutils/pull/11) ([niteshpurohit](https://github.com/niteshpurohit))
|
127
|
+
- Removing code smells [\#9](https://github.com/code-vedas/mutils/pull/9) ([niteshpurohit](https://github.com/niteshpurohit))
|
128
|
+
- Update README.md [\#8](https://github.com/code-vedas/mutils/pull/8) ([niteshpurohit](https://github.com/niteshpurohit))
|
129
|
+
- Update README.md [\#7](https://github.com/code-vedas/mutils/pull/7) ([niteshpurohit](https://github.com/niteshpurohit))
|
130
|
+
- Update README.md [\#6](https://github.com/code-vedas/mutils/pull/6) ([niteshpurohit](https://github.com/niteshpurohit))
|
131
|
+
|
132
|
+
## [0.2.26](https://github.com/code-vedas/mutils/tree/v0.2.26) (2019-11-24)
|
92
133
|
|
134
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.25...v0.2.26)
|
93
135
|
|
136
|
+
## [0.2.25](https://github.com/code-vedas/mutils/tree/v0.2.25) (2019-11-24)
|
137
|
+
|
138
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/885f96959dd3701ac20ed0981b920be753c00db0...v0.2.25)
|
139
|
+
|
140
|
+
**Merged pull requests:**
|
94
141
|
|
95
|
-
|
142
|
+
- Feature/improve concurrency [\#4](https://github.com/code-vedas/mutils/pull/4) ([niteshpurohit](https://github.com/niteshpurohit))
|
143
|
+
- Testing Deploy [\#3](https://github.com/code-vedas/mutils/pull/3) ([niteshpurohit](https://github.com/niteshpurohit))
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mutils (
|
4
|
+
mutils (1.1.0)
|
5
5
|
dry-inflector
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
ast (2.4.1)
|
11
|
+
benchmark-malloc (0.2.0)
|
12
|
+
benchmark-perf (0.6.0)
|
13
|
+
benchmark-trend (0.4.0)
|
10
14
|
coveralls (0.8.23)
|
11
15
|
json (>= 1.8, < 3)
|
12
16
|
simplecov (~> 0.16.1)
|
@@ -17,11 +21,26 @@ GEM
|
|
17
21
|
docile (1.3.2)
|
18
22
|
dry-inflector (0.2.0)
|
19
23
|
json (2.3.0)
|
24
|
+
json (2.3.0-java)
|
25
|
+
parallel (1.19.2)
|
26
|
+
parser (2.7.1.4)
|
27
|
+
ast (~> 2.4.1)
|
28
|
+
pluginator (1.5.0)
|
29
|
+
pre-commit (0.39.0)
|
30
|
+
pluginator (~> 1.5)
|
31
|
+
rainbow (3.0.0)
|
20
32
|
rake (13.0.1)
|
33
|
+
regexp_parser (1.7.1)
|
34
|
+
rexml (3.2.4)
|
21
35
|
rspec (3.9.0)
|
22
36
|
rspec-core (~> 3.9.0)
|
23
37
|
rspec-expectations (~> 3.9.0)
|
24
38
|
rspec-mocks (~> 3.9.0)
|
39
|
+
rspec-benchmark (0.6.0)
|
40
|
+
benchmark-malloc (~> 0.2)
|
41
|
+
benchmark-perf (~> 0.6)
|
42
|
+
benchmark-trend (~> 0.4)
|
43
|
+
rspec (>= 3.0)
|
25
44
|
rspec-core (3.9.1)
|
26
45
|
rspec-support (~> 3.9.1)
|
27
46
|
rspec-expectations (3.9.1)
|
@@ -32,6 +51,18 @@ GEM
|
|
32
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
33
52
|
rspec-support (~> 3.9.0)
|
34
53
|
rspec-support (3.9.2)
|
54
|
+
rubocop (0.89.1)
|
55
|
+
parallel (~> 1.10)
|
56
|
+
parser (>= 2.7.1.1)
|
57
|
+
rainbow (>= 2.2.2, < 4.0)
|
58
|
+
regexp_parser (>= 1.7)
|
59
|
+
rexml
|
60
|
+
rubocop-ast (>= 0.3.0, < 1.0)
|
61
|
+
ruby-progressbar (~> 1.7)
|
62
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
63
|
+
rubocop-ast (0.3.0)
|
64
|
+
parser (>= 2.7.1.4)
|
65
|
+
ruby-progressbar (1.10.1)
|
35
66
|
simplecov (0.16.1)
|
36
67
|
docile (~> 1.1)
|
37
68
|
json (>= 1.8, < 3)
|
@@ -43,17 +74,22 @@ GEM
|
|
43
74
|
thor (1.0.1)
|
44
75
|
tins (1.24.1)
|
45
76
|
sync
|
77
|
+
unicode-display_width (1.7.0)
|
46
78
|
|
47
79
|
PLATFORMS
|
80
|
+
java
|
48
81
|
ruby
|
49
82
|
|
50
83
|
DEPENDENCIES
|
51
84
|
bundler (~> 2.0)
|
52
85
|
coveralls
|
53
86
|
mutils!
|
87
|
+
pre-commit
|
54
88
|
rake (~> 13.0)
|
55
89
|
rspec
|
90
|
+
rspec-benchmark
|
56
91
|
rspec-json_expectations
|
92
|
+
rubocop
|
57
93
|
|
58
94
|
BUNDLED WITH
|
59
95
|
2.1.4
|
data/README.md
CHANGED
@@ -1,13 +1,34 @@
|
|
1
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/
|
1
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/42e8a34f839ca0c5ec45/maintainability)](https://codeclimate.com/github/code-vedas/mutils/maintainability)
|
2
2
|
![](https://ruby-gem-downloads-badge.herokuapp.com/mutils?type=total&color=brightgreen)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/mutils.svg)](https://badge.fury.io/rb/mutils)
|
4
|
-
[![Coverage Status](https://coveralls.io/repos/github/
|
5
|
-
[![Build Status](https://travis-ci.com/
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/Code-Vedas/mutils/badge.svg?branch=master)](https://coveralls.io/github/Code-Vedas/mutils?branch=master)
|
5
|
+
[![Build Status](https://travis-ci.com/code-vedas/mutils.svg?branch=master)](https://travis-ci.com/code-vedas/mutils)
|
6
6
|
# Mutils
|
7
7
|
## Introduction
|
8
8
|
`mutils` is collection of useful modules for `ruby on rails` which is tested and benchmarked against high load.
|
9
9
|
|
10
10
|
These collection of modules are built by developer for developers :-)
|
11
|
+
# Table of Contents
|
12
|
+
|
13
|
+
* [Features](#features)
|
14
|
+
* [Installation](#installation)
|
15
|
+
* [Usage](#usage)
|
16
|
+
* [Rails Generator](#rails-generator)
|
17
|
+
* [Attributes](#attributes)
|
18
|
+
* [Relations](#relations)
|
19
|
+
* [Conditional Attributes](#conditional-attributes)
|
20
|
+
* [Conditional Relations](#conditional-relations)
|
21
|
+
* [Attributes Block](#attributes-blocks)
|
22
|
+
* [Attributes Block with Params](#attributes-blocks-with-params)
|
23
|
+
* [Custom Methods](#custom-methods)
|
24
|
+
* [Name Tag](#name-tag)
|
25
|
+
* [Sample Usage](#sample-usage)
|
26
|
+
|
27
|
+
## Features
|
28
|
+
* Simple declaration syntax similar to Active Model Serializer
|
29
|
+
* Realtionships support `belongs_to`, `has_many`, `has_one`
|
30
|
+
* Block style attributes with params
|
31
|
+
|
11
32
|
## Installation
|
12
33
|
|
13
34
|
Add this line to your application's Gemfile:
|
@@ -22,16 +43,9 @@ Or install it yourself as:
|
|
22
43
|
|
23
44
|
$ gem install mutils
|
24
45
|
|
25
|
-
##
|
26
|
-
| Sno | Name | Status |
|
27
|
-
|:---: |:-----------------: |:------: |
|
28
|
-
| 1 | Serializer - JSON | Done |
|
46
|
+
## Usage
|
29
47
|
|
30
|
-
|
31
|
-
### Serializer - JSON
|
32
|
-
JSON Serializer for Active Models
|
33
|
-
|
34
|
-
#### Generate Serializer by command
|
48
|
+
### Rails Generator
|
35
49
|
```shell script
|
36
50
|
rails g mutils:serializer User id first_name last_name email
|
37
51
|
|
@@ -49,15 +63,7 @@ class UserSerializer < Mutils::Serialization::BaseSerializer
|
|
49
63
|
end
|
50
64
|
```
|
51
65
|
|
52
|
-
|
53
|
-
1. Attributes
|
54
|
-
2. Relations
|
55
|
-
3. Conditional Attributes
|
56
|
-
4. Conditional Relations
|
57
|
-
5. Custom Methods
|
58
|
-
6. name_tag
|
59
|
-
|
60
|
-
##### Attributes
|
66
|
+
### Attributes
|
61
67
|
Attributes are fields in the model itself. You can reference them by below example
|
62
68
|
```ruby
|
63
69
|
# frozen_string_literal: true
|
@@ -69,7 +75,7 @@ class UserSerializer < Mutils::Serialization::BaseSerializer
|
|
69
75
|
attribute :email, {always_include: true} ## this will allow to selectively include email
|
70
76
|
end
|
71
77
|
```
|
72
|
-
|
78
|
+
### Relations
|
73
79
|
Relations such as `has_many`, `belongs_to`, `has_one` can be used as follows
|
74
80
|
1. Every relation must be provided with their own serializer
|
75
81
|
2. `always_include` option can be used to instruct `Serializer` to always include this relation
|
@@ -83,7 +89,7 @@ class UserSerializer < Mutils::Serialization::BaseSerializer
|
|
83
89
|
attributes :id, :first_name, :last_name, :email
|
84
90
|
|
85
91
|
belongs_to :company, serializer: CompanySerializer, always_include: true
|
86
|
-
##OR
|
92
|
+
## OR
|
87
93
|
belongs_to :company, serializer: CompanySerializer, always_include: true, label: 'organization' ##<== important to give singular name
|
88
94
|
|
89
95
|
has_many :comments, serializer: CommentSerializer
|
@@ -94,8 +100,12 @@ class UserSerializer < Mutils::Serialization::BaseSerializer
|
|
94
100
|
end
|
95
101
|
end
|
96
102
|
```
|
97
|
-
|
98
|
-
|
103
|
+
### Conditional Attributes
|
104
|
+
Serializer can have conditional attributes with `if: Proc`
|
105
|
+
`if: Proc` block can receive `scope` and `params` as arguments
|
106
|
+
|
107
|
+
- __in proc {|scope|}__, scope is object which is being serialized
|
108
|
+
- __in proc {|scope,params|}__, scope is object which is being serialized and params is hash given to Serializer as second arguments in {params:anything}
|
99
109
|
```ruby
|
100
110
|
# frozen_string_literal: true
|
101
111
|
|
@@ -103,11 +113,20 @@ Attributes are fields in the model itself. You can reference them by below examp
|
|
103
113
|
class UserSerializer < Mutils::Serialization::BaseSerializer
|
104
114
|
attributes :id, :first_name, :last_name
|
105
115
|
attribute :email, if: proc { |scope| scope.name == 'mutils' } ## Email will only serialize if user's name is 'mutils'
|
116
|
+
# OR with Params
|
117
|
+
attribute :email, if: proc { |scope,params| params && params[:show_email] == true } ## Email will only serialize if params[:show_email] is true
|
106
118
|
end
|
119
|
+
|
120
|
+
UserSerializer.new(user) # Without params
|
121
|
+
UserSerializer.new(user,{params:{show_email:true}}) # With params
|
107
122
|
```
|
108
|
-
|
109
|
-
|
110
|
-
|
123
|
+
|
124
|
+
### Conditional Relations
|
125
|
+
Serializer can have conditional relations with `if: Proc`
|
126
|
+
`if: Proc` block can receive `scope` and `params` as arguments
|
127
|
+
|
128
|
+
- __in proc {|scope|}__, scope is object which is being serialized
|
129
|
+
- __in proc {|scope,params|}__, scope is object which is being serialized and params is hash given to Serializer as second arguments in {params:anything}
|
111
130
|
```ruby
|
112
131
|
# frozen_string_literal: true
|
113
132
|
|
@@ -116,10 +135,49 @@ class UserSerializer < Mutils::Serialization::BaseSerializer
|
|
116
135
|
attributes :id, :first_name, :last_name
|
117
136
|
has_many :comments, serializer: CommentSerializer, if: proc { |scope| scope.name == 'mutils' } ## comments will only serialize if user's name is 'mutils'
|
118
137
|
belongs_to :account, serializer: AccountSerializer, if: proc { |scope| scope.name != 'mutils' } ## account will only serialize if user's name is not 'mutils'
|
138
|
+
# OR with Params
|
139
|
+
belongs_to :account, serializer: AccountSerializer, if: proc { |scope,params| params && params[:show_account] == true } ## account will only serialize if params[:show_account] is true
|
119
140
|
end
|
141
|
+
|
142
|
+
UserSerializer.new(user) # Without params
|
143
|
+
UserSerializer.new(user,{params:{show_account:true}}) # With params
|
144
|
+
|
120
145
|
```
|
121
|
-
|
122
|
-
|
146
|
+
|
147
|
+
### Attributes Blocks
|
148
|
+
While writting attribute a block can be provided for useful transformations like `full_name` as shown below
|
149
|
+
```ruby
|
150
|
+
# frozen_string_literal: true
|
151
|
+
|
152
|
+
# User Serializer
|
153
|
+
class UserSerializer < Mutils::Serialization::BaseSerializer
|
154
|
+
attributes :id, :first_name, :last_name, :email
|
155
|
+
attribute :full_name do |object|
|
156
|
+
"#{object.first_name} #{object.last_name}"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
```
|
160
|
+
### Attributes Blocks with Params
|
161
|
+
While writting attribute a block can be provided for useful transformations like `full_name` as shown below
|
162
|
+
```ruby
|
163
|
+
# frozen_string_literal: true
|
164
|
+
|
165
|
+
# User Serializer
|
166
|
+
class UserSerializer < Mutils::Serialization::BaseSerializer
|
167
|
+
attributes :id, :first_name, :last_name, :email
|
168
|
+
attribute :is_owner do |object,params|
|
169
|
+
params[:owner].id == object.id ? true:false
|
170
|
+
end
|
171
|
+
end
|
172
|
+
```
|
173
|
+
```ruby
|
174
|
+
# in controller
|
175
|
+
|
176
|
+
user = current_user
|
177
|
+
owner = owner_user
|
178
|
+
render json: UserSerializer.new(user,{params:{owner:owner}})
|
179
|
+
```
|
180
|
+
### Custom Methods
|
123
181
|
Custom methods used in Serializer can be useful for cases as below.
|
124
182
|
`scope` will be available to reference object in Serializer in below case its `user`
|
125
183
|
|
@@ -140,7 +198,7 @@ class UserSerializer < Mutils::Serialization::BaseSerializer
|
|
140
198
|
end
|
141
199
|
end
|
142
200
|
```
|
143
|
-
|
201
|
+
### Name Tag
|
144
202
|
name_tag is used to provide custom name to serializer output keys for json
|
145
203
|
|
146
204
|
**Options**
|
@@ -163,20 +221,20 @@ class UserSerializer < Mutils::Serialization::BaseSerializer
|
|
163
221
|
end
|
164
222
|
```
|
165
223
|
|
166
|
-
|
224
|
+
### Sample Usage
|
167
225
|
|
168
226
|
```ruby
|
169
227
|
user = User.first
|
170
228
|
options = {includes: [:comments,:account]}
|
171
229
|
UserSerializer.new(user,options).to_h
|
172
230
|
```
|
173
|
-
###or
|
231
|
+
### or
|
174
232
|
```ruby
|
175
233
|
users = User.all
|
176
234
|
options = {includes: [:account]}
|
177
235
|
UserSerializer.new(users,options).to_json
|
178
236
|
```
|
179
|
-
###or in controllers
|
237
|
+
### or in controllers
|
180
238
|
```ruby
|
181
239
|
users = User.all
|
182
240
|
options = {includes: [:account]}
|
@@ -194,4 +252,8 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
194
252
|
|
195
253
|
## Code of Conduct
|
196
254
|
|
197
|
-
Everyone interacting in the Mutils project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
255
|
+
Everyone interacting in the Mutils project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/code-vedas/mutils/blob/master/CODE_OF_CONDUCT.md).
|
256
|
+
|
257
|
+
## Security
|
258
|
+
|
259
|
+
For security refer to [security](https://github.com/Code-Vedas/mutils/blob/master/SECURITY.md) document.
|