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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 228adb9ade738e5407a5ae9a5703f7cf5b45af69
4
- data.tar.gz: 61fdfbc616b39f2fcd354220d31e8bec9e7820b3
3
+ metadata.gz: 1b9c37e4c95b76725a1cd1c63fe6f065dc56eb04
4
+ data.tar.gz: c206e1fec888ce0031ad4c2c5d26a2519a82791c
5
5
  SHA512:
6
- metadata.gz: a9ca0d04854314ef0df6f5566ea7edbfb3c8767487e7de9376f99b3e36d5e96bbc87a20b54aae4a911feb841709fd13411f57cc35913011348077c66e96f3049
7
- data.tar.gz: c8368190cf3edf7bb23b98949c1444e8b5df018c56658f4d8f8a905d4cdce7e5c37008227aaaec7c1d740eecf12885713297fc6e1799f3cda2c6b6eebb9da45b
6
+ metadata.gz: c8f727dc37c485ba63ccb9de5abfa3903ea3369c4ea1a7175d796d00a63b971913672d5c33b0685b87b873ba586e1caba4b1a5ce5761961151a7bf4287c6ff63
7
+ data.tar.gz: c5c6a4dc06ad88949d1d18ffbc23b0447a8843c9e658ae386d3eb510af36448de75f749b6f20076b46f1b294802dbc1366f25ed0bbfd5fb6a6861676cb464d16
@@ -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: "#{format_key(attr_key)} - #{message}",
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
@@ -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)).delete(key)
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
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Resources
3
- VERSION = '0.9.2'
3
+ VERSION = '0.9.3'
4
4
  end
5
5
  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.2
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-18 00:00:00.000000000 Z
12
+ date: 2018-08-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler