jsonapi_errorable 0.1.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa0ecb4a40f4cd0870f4132a5e948b65ee56510f
4
- data.tar.gz: c93ca5167b0e41b988d0eeb591676813bc6d2e25
3
+ metadata.gz: 63b8a3652fd9414efabf6132a0f6271570b2463e
4
+ data.tar.gz: c40c41cc6bacf302bdc1c11ac5a2da11a4b5f92c
5
5
  SHA512:
6
- metadata.gz: a2597392e7680bb538e3f8ba039e46c9417f61f9496987d9f5cd635c70319d9b1bd12dd418f17d97481d1cf59d021c7f51755585bed537f61b4643434fc27a97
7
- data.tar.gz: a37e24945ad49f2be444a68791135a8aeb2428ecc1095e3aa618e707ee3f80c806dd9fef64ad3f6116f1d78ee08b8a6752118ab1bf76a5f846e0259f7ded31c4
6
+ metadata.gz: 18531dd8ed2e9f13613008feab5479778b3d364178883812865d0c794c690e48e704d304e7f68012303876a166e741ccc41f991592d9cbbfb319cc6086661dd0
7
+ data.tar.gz: c0ba639d7807955bc3eead312d6c63d24de0a36f6a4d05179dc88679e44ebdc322ad40fb02eeda167d7e0b2951f67685ff040a6b73cecc3d0e5b8beec79e1559
@@ -1,17 +1,21 @@
1
1
  module JsonapiErrorable
2
2
  module Serializers
3
- class SerializableValidation < JSONAPI::Serializable::Resource
4
- type :validation_errors
3
+ class Validation
4
+ attr_reader :object
5
5
 
6
- attribute :errors do
7
- @object.errors.to_hash.map do |attribute, messages|
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(@object, attribute) },
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 = @object.class.reflect_on_all_associations.map(&:name)
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
- @object.respond_to?(name)
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: record,
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
@@ -1,3 +1,3 @@
1
1
  module JsonapiErrorable
2
- VERSION = "0.1.2"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -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/serializable_validation'
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.1.2
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-03-14 00:00:00.000000000 Z
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/serializable_validation.rb
143
+ - lib/jsonapi_errorable/serializers/validation.rb
144
144
  - lib/jsonapi_errorable/validatable.rb
145
145
  - lib/jsonapi_errorable/version.rb
146
146
  homepage: