mutils 0.2.36 → 0.2.37
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/.travis.yml +7 -9
- data/CHANGELOG.md +60 -41
- data/Gemfile.lock +2 -0
- data/README.md +67 -28
- data/lib/mutils/serialization/serialization_includes.rb +2 -1
- data/lib/mutils/serialization/serialization_methods.rb +9 -2
- data/lib/mutils/serialization/serialization_results.rb +10 -1
- data/lib/mutils/version.rb +1 -1
- data/mutils.gemspec +4 -4
- metadata +5 -6
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 926c4b4de85c53430599d8d3f0bedc06992bba7475f5bfb63c17c0149b9f5e7c
|
|
4
|
+
data.tar.gz: 510912f1df040bb65dc4b13d92c7e1e9c3cd976bd29a089dd87449bae7a58813
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 93232e13da63e6c1dd76a44e0bbce37a0fd0ef030bca6b099c47e8529e4ea4522edcf0b5aaca07c19e9aaba9cf0c9febbfceef651544aadbf5170395c444dd64
|
|
7
|
+
data.tar.gz: d9fdd7f409e3c7d9dde57ed7a59504aca0145c2dc93f054cd9a6e75b390940f111fb827e352c7510b46864f37175abd266b0f40407b9c4414e6207cdd1baca75
|
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/.travis.yml
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
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
|
+
script: bundle exec rspec
|
|
15
16
|
branches:
|
|
16
17
|
only: master
|
|
17
|
-
|
|
18
|
-
allow_failures:
|
|
19
|
-
- rvm: jruby-9.2
|
|
20
|
-
fast_finish: true
|
|
18
|
+
bundler_args: --with=development,test --jobs=3 --retry=3
|
data/CHANGELOG.md
CHANGED
|
@@ -1,95 +1,114 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [v0.2.
|
|
3
|
+
## [v0.2.36](https://github.com/code-vedas/mutils/tree/v0.2.36) (2020-04-14)
|
|
4
4
|
|
|
5
|
-
[Full Changelog](https://github.com/
|
|
5
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.35...v0.2.36)
|
|
6
6
|
|
|
7
7
|
**Merged pull requests:**
|
|
8
8
|
|
|
9
|
-
-
|
|
9
|
+
- Remove active support dep [\#34](https://github.com/code-vedas/mutils/pull/34) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
10
|
+
- Conditional attributes and relations [\#32](https://github.com/code-vedas/mutils/pull/32) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
11
|
+
- chore: add more ruby version and os to test [\#31](https://github.com/code-vedas/mutils/pull/31) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
10
12
|
|
|
11
|
-
## [v0.2.
|
|
13
|
+
## [v0.2.35](https://github.com/code-vedas/mutils/tree/v0.2.35) (2020-03-30)
|
|
12
14
|
|
|
13
|
-
[Full Changelog](https://github.com/
|
|
15
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.34...v0.2.35)
|
|
14
16
|
|
|
15
17
|
**Merged pull requests:**
|
|
16
18
|
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
- changelog: v0.2.32 [\#22](https://github.com/niteshpurohit/mutils/pull/22) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
19
|
+
- new option 'label' for relations [\#30](https://github.com/code-vedas/mutils/pull/30) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
20
|
+
- added custom\_method and attribute example [\#29](https://github.com/code-vedas/mutils/pull/29) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
21
|
+
- chore: update changelog [\#28](https://github.com/code-vedas/mutils/pull/28) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
21
22
|
|
|
22
|
-
## [v0.2.
|
|
23
|
+
## [v0.2.34](https://github.com/code-vedas/mutils/tree/v0.2.34) (2020-03-29)
|
|
23
24
|
|
|
24
|
-
[Full Changelog](https://github.com/
|
|
25
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.33...v0.2.34)
|
|
25
26
|
|
|
26
27
|
**Merged pull requests:**
|
|
27
28
|
|
|
28
|
-
- Feature/
|
|
29
|
+
- Feature/attribute can be optional [\#27](https://github.com/code-vedas/mutils/pull/27) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
29
30
|
|
|
30
|
-
## [v0.2.
|
|
31
|
+
## [v0.2.33](https://github.com/code-vedas/mutils/tree/v0.2.33) (2020-03-29)
|
|
31
32
|
|
|
32
|
-
[Full Changelog](https://github.com/
|
|
33
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.32...v0.2.33)
|
|
33
34
|
|
|
34
35
|
**Merged pull requests:**
|
|
35
36
|
|
|
36
|
-
-
|
|
37
|
-
-
|
|
37
|
+
- 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))
|
|
38
|
+
- Update CHANGELOG.md [\#25](https://github.com/code-vedas/mutils/pull/25) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
39
|
+
- Create .codeclimate.yml [\#24](https://github.com/code-vedas/mutils/pull/24) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
40
|
+
- changelog: v0.2.32 [\#22](https://github.com/code-vedas/mutils/pull/22) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
38
41
|
|
|
39
|
-
## [v0.2.
|
|
42
|
+
## [v0.2.32](https://github.com/code-vedas/mutils/tree/v0.2.32) (2020-03-18)
|
|
40
43
|
|
|
41
|
-
[Full Changelog](https://github.com/
|
|
44
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.31...v0.2.32)
|
|
42
45
|
|
|
43
46
|
**Merged pull requests:**
|
|
44
47
|
|
|
45
|
-
-
|
|
48
|
+
- Feature/improve performance [\#21](https://github.com/code-vedas/mutils/pull/21) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
46
49
|
|
|
47
|
-
## [v0.2.
|
|
50
|
+
## [v0.2.31](https://github.com/code-vedas/mutils/tree/v0.2.31) (2020-03-18)
|
|
48
51
|
|
|
49
|
-
[Full Changelog](https://github.com/
|
|
52
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.30...v0.2.31)
|
|
50
53
|
|
|
51
54
|
**Merged pull requests:**
|
|
52
55
|
|
|
53
|
-
-
|
|
56
|
+
- Update version.rb [\#20](https://github.com/code-vedas/mutils/pull/20) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
57
|
+
- Rake 13.0 [\#19](https://github.com/code-vedas/mutils/pull/19) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
54
58
|
|
|
55
|
-
## [v0.2.
|
|
59
|
+
## [v0.2.30](https://github.com/code-vedas/mutils/tree/v0.2.30) (2020-03-17)
|
|
56
60
|
|
|
57
|
-
[Full Changelog](https://github.com/
|
|
61
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.29...v0.2.30)
|
|
62
|
+
|
|
63
|
+
**Merged pull requests:**
|
|
64
|
+
|
|
65
|
+
- Deps [\#18](https://github.com/code-vedas/mutils/pull/18) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
66
|
+
|
|
67
|
+
## [v0.2.29](https://github.com/code-vedas/mutils/tree/v0.2.29) (2019-12-07)
|
|
68
|
+
|
|
69
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.28...v0.2.29)
|
|
70
|
+
|
|
71
|
+
**Merged pull requests:**
|
|
72
|
+
|
|
73
|
+
- Scope Variable bug [\#14](https://github.com/code-vedas/mutils/pull/14) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
74
|
+
|
|
75
|
+
## [v0.2.28](https://github.com/code-vedas/mutils/tree/v0.2.28) (2019-11-26)
|
|
76
|
+
|
|
77
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.27...v0.2.28)
|
|
58
78
|
|
|
59
79
|
**Implemented enhancements:**
|
|
60
80
|
|
|
61
|
-
- Feature/scoped generator [\#13](https://github.com/
|
|
81
|
+
- Feature/scoped generator [\#13](https://github.com/code-vedas/mutils/pull/13) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
62
82
|
|
|
63
|
-
## [v0.2.27](https://github.com/
|
|
83
|
+
## [v0.2.27](https://github.com/code-vedas/mutils/tree/v0.2.27) (2019-11-25)
|
|
64
84
|
|
|
65
|
-
[Full Changelog](https://github.com/
|
|
85
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.26...v0.2.27)
|
|
66
86
|
|
|
67
87
|
**Implemented enhancements:**
|
|
68
88
|
|
|
69
|
-
- feat: coveralls added [\#5](https://github.com/
|
|
89
|
+
- feat: coveralls added [\#5](https://github.com/code-vedas/mutils/pull/5) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
70
90
|
|
|
71
91
|
**Merged pull requests:**
|
|
72
92
|
|
|
73
|
-
- Update CHANGELOG.md [\#12](https://github.com/
|
|
74
|
-
- Update version.rb [\#11](https://github.com/
|
|
75
|
-
- Removing code smells [\#9](https://github.com/
|
|
76
|
-
- Update README.md [\#8](https://github.com/
|
|
77
|
-
- Update README.md [\#7](https://github.com/
|
|
78
|
-
- Update README.md [\#6](https://github.com/
|
|
93
|
+
- Update CHANGELOG.md [\#12](https://github.com/code-vedas/mutils/pull/12) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
94
|
+
- Update version.rb [\#11](https://github.com/code-vedas/mutils/pull/11) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
95
|
+
- Removing code smells [\#9](https://github.com/code-vedas/mutils/pull/9) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
96
|
+
- Update README.md [\#8](https://github.com/code-vedas/mutils/pull/8) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
97
|
+
- Update README.md [\#7](https://github.com/code-vedas/mutils/pull/7) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
98
|
+
- Update README.md [\#6](https://github.com/code-vedas/mutils/pull/6) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
79
99
|
|
|
80
|
-
## [v0.2.26](https://github.com/
|
|
100
|
+
## [v0.2.26](https://github.com/code-vedas/mutils/tree/v0.2.26) (2019-11-24)
|
|
81
101
|
|
|
82
|
-
[Full Changelog](https://github.com/
|
|
102
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/v0.2.25...v0.2.26)
|
|
83
103
|
|
|
84
|
-
## [v0.2.25](https://github.com/
|
|
104
|
+
## [v0.2.25](https://github.com/code-vedas/mutils/tree/v0.2.25) (2019-11-24)
|
|
85
105
|
|
|
86
|
-
[Full Changelog](https://github.com/
|
|
106
|
+
[Full Changelog](https://github.com/code-vedas/mutils/compare/885f96959dd3701ac20ed0981b920be753c00db0...v0.2.25)
|
|
87
107
|
|
|
88
108
|
**Merged pull requests:**
|
|
89
109
|
|
|
90
|
-
- Feature/improve concurrency [\#4](https://github.com/
|
|
91
|
-
- Testing Deploy [\#3](https://github.com/
|
|
92
|
-
|
|
110
|
+
- Feature/improve concurrency [\#4](https://github.com/code-vedas/mutils/pull/4) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
111
|
+
- Testing Deploy [\#3](https://github.com/code-vedas/mutils/pull/3) ([niteshpurohit](https://github.com/niteshpurohit))
|
|
93
112
|
|
|
94
113
|
|
|
95
114
|
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
|
-
[](https://codeclimate.com/github/code-vedas/mutils/maintainability)
|
|
2
2
|

|
|
3
3
|
[](https://badge.fury.io/rb/mutils)
|
|
4
|
-
[](https://coveralls.io/github/Code-Vedas/mutils?branch=master)
|
|
5
|
+
[](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 |
|
|
29
|
-
|
|
30
|
-
## Usage
|
|
31
|
-
### Serializer - JSON
|
|
32
|
-
JSON Serializer for Active Models
|
|
46
|
+
## Usage
|
|
33
47
|
|
|
34
|
-
|
|
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
|
|
@@ -94,7 +100,7 @@ class UserSerializer < Mutils::Serialization::BaseSerializer
|
|
|
94
100
|
end
|
|
95
101
|
end
|
|
96
102
|
```
|
|
97
|
-
|
|
103
|
+
### Conditional Attributes
|
|
98
104
|
Attributes are fields in the model itself. You can reference them by below example
|
|
99
105
|
```ruby
|
|
100
106
|
# frozen_string_literal: true
|
|
@@ -106,7 +112,7 @@ class UserSerializer < Mutils::Serialization::BaseSerializer
|
|
|
106
112
|
end
|
|
107
113
|
```
|
|
108
114
|
in proc {|scope|}, scope is object which is being serialized
|
|
109
|
-
|
|
115
|
+
### Conditional Relations
|
|
110
116
|
Attributes are fields in the model itself. You can reference them by below example
|
|
111
117
|
```ruby
|
|
112
118
|
# frozen_string_literal: true
|
|
@@ -119,7 +125,40 @@ class UserSerializer < Mutils::Serialization::BaseSerializer
|
|
|
119
125
|
end
|
|
120
126
|
```
|
|
121
127
|
in proc {|scope|}, scope is object which is being serialized
|
|
122
|
-
|
|
128
|
+
### Attributes Blocks
|
|
129
|
+
While writting attribute a block can be provided for useful transformations like `full_name` as shown below
|
|
130
|
+
```ruby
|
|
131
|
+
# frozen_string_literal: true
|
|
132
|
+
|
|
133
|
+
# User Serializer
|
|
134
|
+
class UserSerializer < Mutils::Serialization::BaseSerializer
|
|
135
|
+
attributes :id, :first_name, :last_name, :email
|
|
136
|
+
attribute :full_name do |object|
|
|
137
|
+
"#{object.first_name} #{object.last_name}"
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
```
|
|
141
|
+
### Attributes Blocks with Params
|
|
142
|
+
While writting attribute a block can be provided for useful transformations like `full_name` as shown below
|
|
143
|
+
```ruby
|
|
144
|
+
# frozen_string_literal: true
|
|
145
|
+
|
|
146
|
+
# User Serializer
|
|
147
|
+
class UserSerializer < Mutils::Serialization::BaseSerializer
|
|
148
|
+
attributes :id, :first_name, :last_name, :email
|
|
149
|
+
attribute :is_owner do |object,params|
|
|
150
|
+
params[:owner].id == object.id ? true:false
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
```
|
|
154
|
+
```ruby
|
|
155
|
+
# in controller
|
|
156
|
+
|
|
157
|
+
user = current_user
|
|
158
|
+
owner = owner_user
|
|
159
|
+
render json: UserSerializer.new(user,{params:{owner:owner}})
|
|
160
|
+
```
|
|
161
|
+
### Custom Methods
|
|
123
162
|
Custom methods used in Serializer can be useful for cases as below.
|
|
124
163
|
`scope` will be available to reference object in Serializer in below case its `user`
|
|
125
164
|
|
|
@@ -140,7 +179,7 @@ class UserSerializer < Mutils::Serialization::BaseSerializer
|
|
|
140
179
|
end
|
|
141
180
|
end
|
|
142
181
|
```
|
|
143
|
-
|
|
182
|
+
### Name Tag
|
|
144
183
|
name_tag is used to provide custom name to serializer output keys for json
|
|
145
184
|
|
|
146
185
|
**Options**
|
|
@@ -163,7 +202,7 @@ class UserSerializer < Mutils::Serialization::BaseSerializer
|
|
|
163
202
|
end
|
|
164
203
|
```
|
|
165
204
|
|
|
166
|
-
|
|
205
|
+
### Sample Usage
|
|
167
206
|
|
|
168
207
|
```ruby
|
|
169
208
|
user = User.first
|
|
@@ -194,4 +233,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
194
233
|
|
|
195
234
|
## Code of Conduct
|
|
196
235
|
|
|
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/
|
|
236
|
+
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).
|
|
@@ -8,6 +8,7 @@ module Mutils
|
|
|
8
8
|
def self.included(base)
|
|
9
9
|
base.extend ClassMethods
|
|
10
10
|
end
|
|
11
|
+
|
|
11
12
|
# Module ClassMethods
|
|
12
13
|
module ClassMethods
|
|
13
14
|
def name_tag(name_tag, root = nil)
|
|
@@ -31,10 +32,16 @@ module Mutils
|
|
|
31
32
|
end
|
|
32
33
|
end
|
|
33
34
|
|
|
34
|
-
def attribute(method_name, options = {})
|
|
35
|
+
def attribute(method_name, options = {}, &proc)
|
|
35
36
|
raise "if: should be a Proc object for attribute #{method_name}" if options[:if] && (options[:if].class.to_s != 'Proc')
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
if proc.class.to_s == 'Proc'
|
|
39
|
+
self.attributes_to_serialize_blocks = {} if attributes_to_serialize_blocks.nil?
|
|
40
|
+
options[:block] = proc
|
|
41
|
+
attributes_to_serialize_blocks[method_name] = options
|
|
42
|
+
else
|
|
43
|
+
add_single_attribute(method_name, options, 'attribute')
|
|
44
|
+
end
|
|
38
45
|
end
|
|
39
46
|
|
|
40
47
|
def custom_method(method_name, options = {})
|
|
@@ -19,10 +19,19 @@ module Mutils
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def hashed_result
|
|
22
|
-
[
|
|
22
|
+
[fetch_block_attributes(self.class.attributes_to_serialize_blocks),
|
|
23
|
+
fetch_attributes(self.class.attributes_to_serialize),
|
|
23
24
|
hash_relationships(self.class.relationships)].reduce(&:merge)
|
|
24
25
|
end
|
|
25
26
|
|
|
27
|
+
def fetch_block_attributes(attributes)
|
|
28
|
+
hash = {}
|
|
29
|
+
attributes&.keys&.each do |key|
|
|
30
|
+
hash[key] = attributes[key][:block].call(scope, options[:params])
|
|
31
|
+
end
|
|
32
|
+
hash
|
|
33
|
+
end
|
|
34
|
+
|
|
26
35
|
def fetch_attributes(attributes)
|
|
27
36
|
hash = {}
|
|
28
37
|
attributes&.keys&.each do |key|
|
data/lib/mutils/version.rb
CHANGED
data/mutils.gemspec
CHANGED
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
|
12
12
|
|
|
13
13
|
spec.summary = 'mutils Utilities for rails app'
|
|
14
14
|
spec.description = 'mutils Utilities for rails app'
|
|
15
|
-
spec.homepage = 'https://github.com/
|
|
15
|
+
spec.homepage = 'https://github.com/code-vedas/mutils'
|
|
16
16
|
spec.license = 'MIT'
|
|
17
17
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
18
18
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.require_paths = ['lib']
|
|
23
23
|
spec.required_ruby_version = '>= 2.5.0'
|
|
24
24
|
spec.required_rubygems_version = '>= 1.8.11'
|
|
25
|
-
spec.
|
|
25
|
+
spec.add_dependency('dry-inflector')
|
|
26
26
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
|
27
27
|
spec.add_development_dependency 'coveralls'
|
|
28
28
|
spec.add_development_dependency 'rake', '~> 13.0'
|
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
|
30
30
|
spec.add_development_dependency 'rspec-json_expectations'
|
|
31
31
|
|
|
32
32
|
spec.metadata = {
|
|
33
|
-
'bug_tracker_uri' => 'https://github.com/
|
|
34
|
-
'source_code_uri' => "https://github.com/
|
|
33
|
+
'bug_tracker_uri' => 'https://github.com/code-vedas/mutils/issues',
|
|
34
|
+
'source_code_uri' => "https://github.com/code-vedas/mutils/tree/v#{Mutils::VERSION}"
|
|
35
35
|
}
|
|
36
36
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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.37
|
|
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-04-
|
|
11
|
+
date: 2020-04-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: dry-inflector
|
|
@@ -113,7 +113,6 @@ files:
|
|
|
113
113
|
- ".rspec"
|
|
114
114
|
- ".rubocop.yml"
|
|
115
115
|
- ".rubocop_todo.yml"
|
|
116
|
-
- ".ruby-version"
|
|
117
116
|
- ".travis.yml"
|
|
118
117
|
- CHANGELOG.md
|
|
119
118
|
- CODE_OF_CONDUCT.md
|
|
@@ -136,12 +135,12 @@ files:
|
|
|
136
135
|
- lib/mutils/serialization/serialization_results.rb
|
|
137
136
|
- lib/mutils/version.rb
|
|
138
137
|
- mutils.gemspec
|
|
139
|
-
homepage: https://github.com/
|
|
138
|
+
homepage: https://github.com/code-vedas/mutils
|
|
140
139
|
licenses:
|
|
141
140
|
- MIT
|
|
142
141
|
metadata:
|
|
143
|
-
bug_tracker_uri: https://github.com/
|
|
144
|
-
source_code_uri: https://github.com/
|
|
142
|
+
bug_tracker_uri: https://github.com/code-vedas/mutils/issues
|
|
143
|
+
source_code_uri: https://github.com/code-vedas/mutils/tree/v0.2.37
|
|
145
144
|
post_install_message:
|
|
146
145
|
rdoc_options: []
|
|
147
146
|
require_paths:
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.7.0
|