jsonapi_errorable 0.1.2 → 0.6.0
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: 63b8a3652fd9414efabf6132a0f6271570b2463e
|
4
|
+
data.tar.gz: c40c41cc6bacf302bdc1c11ac5a2da11a4b5f92c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18531dd8ed2e9f13613008feab5479778b3d364178883812865d0c794c690e48e704d304e7f68012303876a166e741ccc41f991592d9cbbfb319cc6086661dd0
|
7
|
+
data.tar.gz: c0ba639d7807955bc3eead312d6c63d24de0a36f6a4d05179dc88679e44ebdc322ad40fb02eeda167d7e0b2951f67685ff040a6b73cecc3d0e5b8beec79e1559
|
@@ -1,17 +1,21 @@
|
|
1
1
|
module JsonapiErrorable
|
2
2
|
module Serializers
|
3
|
-
class
|
4
|
-
|
3
|
+
class Validation
|
4
|
+
attr_reader :object
|
5
5
|
|
6
|
-
|
7
|
-
@object
|
6
|
+
def initialize(object)
|
7
|
+
@object = object
|
8
|
+
end
|
9
|
+
|
10
|
+
def errors
|
11
|
+
object.errors.to_hash.map do |attribute, messages|
|
8
12
|
messages.map do |message|
|
9
13
|
{
|
10
14
|
code: 'unprocessable_entity',
|
11
15
|
status: '422',
|
12
16
|
title: 'Validation Error',
|
13
17
|
detail: "#{attribute.capitalize} #{message}",
|
14
|
-
source: { pointer: pointer_for(
|
18
|
+
source: { pointer: pointer_for(object, attribute) },
|
15
19
|
meta: { attribute: attribute, message: message }
|
16
20
|
}
|
17
21
|
end
|
@@ -21,12 +25,12 @@ module JsonapiErrorable
|
|
21
25
|
def relationship?(name)
|
22
26
|
return false unless activerecord?
|
23
27
|
|
24
|
-
relation_names =
|
28
|
+
relation_names = object.class.reflect_on_all_associations.map(&:name)
|
25
29
|
relation_names.include?(name)
|
26
30
|
end
|
27
31
|
|
28
32
|
def attribute?(name)
|
29
|
-
|
33
|
+
object.respond_to?(name)
|
30
34
|
end
|
31
35
|
|
32
36
|
private
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module JsonapiErrorable
|
2
2
|
module Validatable
|
3
3
|
def render_errors_for(record)
|
4
|
+
validation = Serializers::Validation.new(record)
|
5
|
+
|
4
6
|
render \
|
5
|
-
json:
|
6
|
-
status: :unprocessable_entity
|
7
|
-
serializer: Serializers::SerializableValidation,
|
8
|
-
adapter: :attributes
|
7
|
+
json: validation.errors,
|
8
|
+
status: :unprocessable_entity
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
data/lib/jsonapi_errorable.rb
CHANGED
@@ -3,7 +3,7 @@ require 'jsonapi/serializable'
|
|
3
3
|
require 'jsonapi_errorable/version'
|
4
4
|
require 'jsonapi_errorable/exception_handler'
|
5
5
|
require 'jsonapi_errorable/validatable'
|
6
|
-
require 'jsonapi_errorable/serializers/
|
6
|
+
require 'jsonapi_errorable/serializers/validation'
|
7
7
|
|
8
8
|
module JsonapiErrorable
|
9
9
|
def self.included(klass)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi_errorable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -140,7 +140,7 @@ files:
|
|
140
140
|
- jsonapi_errorable.gemspec
|
141
141
|
- lib/jsonapi_errorable.rb
|
142
142
|
- lib/jsonapi_errorable/exception_handler.rb
|
143
|
-
- lib/jsonapi_errorable/serializers/
|
143
|
+
- lib/jsonapi_errorable/serializers/validation.rb
|
144
144
|
- lib/jsonapi_errorable/validatable.rb
|
145
145
|
- lib/jsonapi_errorable/version.rb
|
146
146
|
homepage:
|