json_error_serializer 0.3.1 → 0.3.2
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03e04ab44c7efc0022e9c5128f91210b162d6c93
|
4
|
+
data.tar.gz: 58ca9695b486976bdccdff42eb8e77eb771ba5cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 769c6912c6fd31cbbc52d23c266b7daceb7fc86ded0ab19881a621cb8ed1dc7a19ad53aa8a8aa1dd7a8299eabe22e2fccdbf9418061077e95c298bb7cca99ef9
|
7
|
+
data.tar.gz: da6ab3aededa655059b6ddf433ab10e2492f693c37d600f4f0fb889da4fe96cd64d98f79b7bbddc4121efb88e9b3dc3dd386b99b9024c199542f04692b9ef718
|
data/README.md
CHANGED
@@ -45,6 +45,32 @@ HTTP 404 (Not found)
|
|
45
45
|
}
|
46
46
|
```
|
47
47
|
|
48
|
+
Also possible to use in model validation errors:
|
49
|
+
```ruby
|
50
|
+
@user = User.new(user_params)
|
51
|
+
if @user.save
|
52
|
+
# render your OK responce
|
53
|
+
else
|
54
|
+
validate_errors_serialize(@user.errors)
|
55
|
+
end
|
56
|
+
```
|
57
|
+
Result(example):
|
58
|
+
HTTP 409 (Conflict)
|
59
|
+
```json
|
60
|
+
{
|
61
|
+
"errors": [
|
62
|
+
{
|
63
|
+
"id": "email",
|
64
|
+
"title": "Email has already been taken."
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"id": "telephone",
|
68
|
+
"title": "Telephone has already been taken."
|
69
|
+
}
|
70
|
+
]
|
71
|
+
}
|
72
|
+
```
|
73
|
+
|
48
74
|
Available methods refer to the [wiki](https://github.com/Strollager/error_json_serializer/wiki)
|
49
75
|
|
50
76
|
## Contributing
|
@@ -3,8 +3,8 @@ module JsonErrorSerializer
|
|
3
3
|
|
4
4
|
module Controller
|
5
5
|
|
6
|
-
def validate_errors_serialize(errors)
|
7
|
-
render json: JsonErrorSerializer::Extenders::Serialize.serialize(errors), status: :conflict
|
6
|
+
def validate_errors_serialize(errors, options = {})
|
7
|
+
render json: JsonErrorSerializer::Extenders::Serialize.serialize(errors, options), status: :conflict
|
8
8
|
end
|
9
9
|
|
10
10
|
def respond_200(message = nil)
|
@@ -3,7 +3,7 @@ module JsonErrorSerializer
|
|
3
3
|
|
4
4
|
module Serialize
|
5
5
|
|
6
|
-
def self.serialize(errors)
|
6
|
+
def self.serialize(errors, options = {})
|
7
7
|
return if errors.nil?
|
8
8
|
|
9
9
|
json = {}
|
@@ -15,6 +15,11 @@ module JsonErrorSerializer
|
|
15
15
|
end.flatten
|
16
16
|
|
17
17
|
json[:errors] = new_hash
|
18
|
+
|
19
|
+
if options.present?
|
20
|
+
json[options[:key]] = options[:value]
|
21
|
+
end
|
22
|
+
|
18
23
|
json
|
19
24
|
end
|
20
25
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_error_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vadim Stroganov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|