README.md in mutils-0.2.25 vs README.md in mutils-0.2.27
- old
+ new
@@ -1,8 +1,10 @@
-
+[![Maintainability](https://api.codeclimate.com/v1/badges/2c937dd6d25937ec41bd/maintainability)](https://codeclimate.com/github/niteshpurohit/mutils/maintainability)
+![](https://ruby-gem-downloads-badge.herokuapp.com/mutils?type=total&color=brightgreen)
[![Gem Version](https://badge.fury.io/rb/mutils.svg)](https://badge.fury.io/rb/mutils)
-
+[![Coverage Status](https://coveralls.io/repos/github/niteshpurohit/mutils/badge.svg?branch=feature/coverall)](https://coveralls.io/github/niteshpurohit/mutils?branch=feature/coverall)
+[![Build Status](https://travis-ci.com/niteshpurohit/mutils.svg?branch=master)](https://travis-ci.com/niteshpurohit/mutils)
# Mutils
## Introduction
`mutils` is collection of useful modules for `ruby on rails` which is tested and benchmarked against high load.
These collection of modules are built by developer for developers :-)
@@ -21,13 +23,13 @@
$ gem install mutils
## Modules
| Sno | Name | Status |
|:---: |:-----------------: |:------: |
-| 1 | Serializer - JSON | Beta |
-| 2 | Serializer - XML | In-Dev |
-| 3 | Active Storage Helpers | In-Dev |
+| 1 | Serializer - JSON | Done |
+| 2 | Serializer - XML | Done |
+
## Usage
### Serializer - JSON
JSON Serializer for Active Models
#### Generate Serializer by command
@@ -50,10 +52,11 @@
#### Decorations Available
1. Attributes
2. Custom Methods
3. Relations
+3. name_tag
##### Attributes
Attributes are fields in the model itself. You can reference them by below example
```ruby
# frozen_string_literal: true
@@ -99,10 +102,33 @@
def full_name
"#{scope.first_name} #{scope.last_name}"
end
end
```
-Usage: Use anywhere by
+##### name_tag
+name_tag is used to provide custom name to serializer output keys for json or tags for xml
+
+**Options**
+ - ``name_tag 'Person', true`` # Include Person or People in JSON serialization as root, true|false this only implies to root serializer
+ - ``name_tag 'Person', false`` # not Include Person or People in JSON serialization as root, true|false this only implies to root serializer
+ - ``name_tag 'Person'`` # same as ``name_tag 'Person', false``
+ - without name_tag, actual class name of scope object inside serializer will be used
+```ruby
+# frozen_string_literal: true
+
+# User Serializer
+class UserSerializer < Mutils::Serialization::BaseSerializer
+ name_tag 'Person', true
+ attributes :id, :first_name, :last_name, :email
+ custom_methods :full_name
+
+ def full_name
+ "#{scope.first_name} #{scope.last_name}"
+ end
+end
+```
+
+#### Usage: Use anywhere by
```ruby
user = User.first
options = {includes: [:comments,:account]}
UserSerializer.new(user,options).to_h