jsonapi-resources 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jsonapi/exceptions.rb +12 -2
- data/lib/jsonapi/resource.rb +5 -1
- data/lib/jsonapi/resources/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b9c37e4c95b76725a1cd1c63fe6f065dc56eb04
|
4
|
+
data.tar.gz: c206e1fec888ce0031ad4c2c5d26a2519a82791c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8f727dc37c485ba63ccb9de5abfa3903ea3369c4ea1a7175d796d00a63b971913672d5c33b0685b87b873ba586e1caba4b1a5ce5761961151a7bf4287c6ff63
|
7
|
+
data.tar.gz: c5c6a4dc06ad88949d1d18ffbc23b0447a8843c9e658ae386d3eb510af36448de75f749b6f20076b46f1b294802dbc1366f25ed0bbfd5fb6a6861676cb464d16
|
data/lib/jsonapi/exceptions.rb
CHANGED
@@ -448,11 +448,12 @@ module JSONAPI
|
|
448
448
|
end
|
449
449
|
|
450
450
|
class ValidationErrors < Error
|
451
|
-
attr_reader :error_messages, :error_metadata, :resource_relationships
|
451
|
+
attr_reader :error_messages, :error_metadata, :resource_relationships, :resource_class
|
452
452
|
|
453
453
|
def initialize(resource, error_object_overrides = {})
|
454
454
|
@error_messages = resource.model_error_messages
|
455
455
|
@error_metadata = resource.validation_error_metadata
|
456
|
+
@resource_class = resource.class
|
456
457
|
@resource_relationships = resource.class._relationships.keys
|
457
458
|
@key_formatter = JSONAPI.configuration.key_formatter
|
458
459
|
super(error_object_overrides)
|
@@ -474,7 +475,7 @@ module JSONAPI
|
|
474
475
|
create_error_object(code: JSONAPI::VALIDATION_ERROR,
|
475
476
|
status: :unprocessable_entity,
|
476
477
|
title: message,
|
477
|
-
detail:
|
478
|
+
detail: detail(attr_key, message),
|
478
479
|
source: { pointer: pointer(attr_key) },
|
479
480
|
meta: metadata_for(attr_key, message))
|
480
481
|
end
|
@@ -484,7 +485,12 @@ module JSONAPI
|
|
484
485
|
error_metadata[attr_key] ? error_metadata[attr_key][message] : nil
|
485
486
|
end
|
486
487
|
|
488
|
+
def detail(attr_key, message)
|
489
|
+
general_error?(attr_key) ? message : "#{format_key(attr_key)} - #{message}"
|
490
|
+
end
|
491
|
+
|
487
492
|
def pointer(attr_or_relationship_name)
|
493
|
+
return '/data' if general_error?(attr_or_relationship_name)
|
488
494
|
formatted_attr_or_relationship_name = format_key(attr_or_relationship_name)
|
489
495
|
if resource_relationships.include?(attr_or_relationship_name)
|
490
496
|
"/data/relationships/#{formatted_attr_or_relationship_name}"
|
@@ -492,6 +498,10 @@ module JSONAPI
|
|
492
498
|
"/data/attributes/#{formatted_attr_or_relationship_name}"
|
493
499
|
end
|
494
500
|
end
|
501
|
+
|
502
|
+
def general_error?(attr_key)
|
503
|
+
attr_key.to_sym == :base && !resource_class._has_attribute?(attr_key)
|
504
|
+
end
|
495
505
|
end
|
496
506
|
|
497
507
|
class SaveFailed < Error
|
data/lib/jsonapi/resource.rb
CHANGED
@@ -352,7 +352,7 @@ module JSONAPI
|
|
352
352
|
|
353
353
|
@reload_needed = true
|
354
354
|
else
|
355
|
-
@model.public_send(relationship.relation_name(context: @context)).
|
355
|
+
@model.public_send(relationship.relation_name(context: @context)).destroy(key)
|
356
356
|
end
|
357
357
|
|
358
358
|
:completed
|
@@ -911,6 +911,10 @@ module JSONAPI
|
|
911
911
|
default_attribute_options.merge(@_attributes[attr])
|
912
912
|
end
|
913
913
|
|
914
|
+
def _has_attribute?(attr)
|
915
|
+
@_attributes.keys.include?(attr.to_sym)
|
916
|
+
end
|
917
|
+
|
914
918
|
def _updatable_relationships
|
915
919
|
@_relationships.map { |key, _relationship| key }
|
916
920
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Gebhardt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-08-
|
12
|
+
date: 2018-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|