jsonapi_errorable 0.1.1 → 0.1.2

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: 73ec568ac9bdcef2b3216712107e7baea1a64fdb
4
- data.tar.gz: 83d98f0633575e7f885c9eaf4b608988f9fa5218
3
+ metadata.gz: fa0ecb4a40f4cd0870f4132a5e948b65ee56510f
4
+ data.tar.gz: c93ca5167b0e41b988d0eeb591676813bc6d2e25
5
5
  SHA512:
6
- metadata.gz: 4e305fdbf489ffdeead744bc6b9bd451ed882fc110b617ddfff62b539047c8c91fcc7a4700ab7fdb4b33a195ea8332acb230aafa483117a7257dba69ee1af370
7
- data.tar.gz: 74dfcb7ee472baeb352e47facd63a8d930719bc10af1398e258c1c603758571f2a1e7401d11a04db1431b2a629c8b9993305ffce09d748fb3ce52d1bc35ab24e
6
+ metadata.gz: a2597392e7680bb538e3f8ba039e46c9417f61f9496987d9f5cd635c70319d9b1bd12dd418f17d97481d1cf59d021c7f51755585bed537f61b4643434fc27a97
7
+ data.tar.gz: a37e24945ad49f2be444a68791135a8aeb2428ecc1095e3aa618e707ee3f80c806dd9fef64ad3f6116f1d78ee08b8a6752118ab1bf76a5f846e0259f7ded31c4
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency 'rails', [">= 4.1", "< 6"]
22
- spec.add_dependency 'active_model_serializers', '~> 0.10'
22
+ spec.add_dependency 'jsonapi-serializable', '~> 0.1'
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.11"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,36 +1,32 @@
1
1
  module JsonapiErrorable
2
2
  module Serializers
3
- class ValidationSerializer < ActiveModel::Serializer
4
- attribute :errors
3
+ class SerializableValidation < JSONAPI::Serializable::Resource
4
+ type :validation_errors
5
5
 
6
- def errors
7
- object.errors.to_hash.map do |attribute, messages|
6
+ attribute :errors do
7
+ @object.errors.to_hash.map do |attribute, messages|
8
8
  messages.map do |message|
9
9
  {
10
10
  code: 'unprocessable_entity',
11
11
  status: '422',
12
12
  title: 'Validation Error',
13
13
  detail: "#{attribute.capitalize} #{message}",
14
- source: { pointer: pointer_for(object, attribute) },
14
+ source: { pointer: pointer_for(@object, attribute) },
15
15
  meta: { attribute: attribute, message: message }
16
16
  }
17
17
  end
18
18
  end.flatten
19
19
  end
20
20
 
21
- def activerecord?
22
- object.is_a?(ActiveRecord::Base)
23
- end
24
-
25
21
  def relationship?(name)
26
22
  return false unless activerecord?
27
23
 
28
- relation_names = object.class.reflect_on_all_associations.map(&:name)
24
+ relation_names = @object.class.reflect_on_all_associations.map(&:name)
29
25
  relation_names.include?(name)
30
26
  end
31
27
 
32
28
  def attribute?(name)
33
- object.respond_to?(name)
29
+ @object.respond_to?(name)
34
30
  end
35
31
 
36
32
  private
@@ -45,6 +41,10 @@ module JsonapiErrorable
45
41
  "/data/relationships/#{name}"
46
42
  end
47
43
  end
44
+
45
+ def activerecord?
46
+ object.is_a?(ActiveRecord::Base)
47
+ end
48
48
  end
49
49
  end
50
50
  end
@@ -4,7 +4,7 @@ module JsonapiErrorable
4
4
  render \
5
5
  json: record,
6
6
  status: :unprocessable_entity,
7
- serializer: Serializers::ValidationSerializer,
7
+ serializer: Serializers::SerializableValidation,
8
8
  adapter: :attributes
9
9
  end
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module JsonapiErrorable
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,8 +1,9 @@
1
- require 'active_model_serializers'
1
+ require 'jsonapi/serializable'
2
+
2
3
  require 'jsonapi_errorable/version'
3
4
  require 'jsonapi_errorable/exception_handler'
4
5
  require 'jsonapi_errorable/validatable'
5
- require 'jsonapi_errorable/serializers/validation_serializer'
6
+ require 'jsonapi_errorable/serializers/serializable_validation'
6
7
 
7
8
  module JsonapiErrorable
8
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-22 00:00:00.000000000 Z
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -31,19 +31,19 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: '6'
33
33
  - !ruby/object:Gem::Dependency
34
- name: active_model_serializers
34
+ name: jsonapi-serializable
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.10'
39
+ version: '0.1'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0.10'
46
+ version: '0.1'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -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/validation_serializer.rb
143
+ - lib/jsonapi_errorable/serializers/serializable_validation.rb
144
144
  - lib/jsonapi_errorable/validatable.rb
145
145
  - lib/jsonapi_errorable/version.rb
146
146
  homepage:
@@ -163,9 +163,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  version: '0'
164
164
  requirements: []
165
165
  rubyforge_project:
166
- rubygems_version: 2.4.5.1
166
+ rubygems_version: 2.6.7
167
167
  signing_key:
168
168
  specification_version: 4
169
169
  summary: jsonapi.org compatible error handling
170
170
  test_files: []
171
- has_rdoc: