Exception: JSONAPI::Exceptions::ValidationErrors

Inherits:
Error
  • Object
show all
Defined in:
lib/jsonapi/exceptions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ ValidationErrors

Returns a new instance of ValidationErrors.


380
381
382
383
384
385
# File 'lib/jsonapi/exceptions.rb', line 380

def initialize(resource)
  @error_messages = resource.model_error_messages
  @error_metadata = resource.
  @resource_relationships = resource.class._relationships.keys
  @key_formatter = JSONAPI.configuration.key_formatter
end

Instance Attribute Details

#error_messagesObject (readonly)

Returns the value of attribute error_messages


378
379
380
# File 'lib/jsonapi/exceptions.rb', line 378

def error_messages
  @error_messages
end

#error_metadataObject (readonly)

Returns the value of attribute error_metadata


378
379
380
# File 'lib/jsonapi/exceptions.rb', line 378

def 
  @error_metadata
end

#resource_relationshipsObject (readonly)

Returns the value of attribute resource_relationships


378
379
380
# File 'lib/jsonapi/exceptions.rb', line 378

def resource_relationships
  @resource_relationships
end

Instance Method Details

#errorsObject


391
392
393
394
395
# File 'lib/jsonapi/exceptions.rb', line 391

def errors
  error_messages.flat_map do |attr_key, messages|
    messages.map { |message| json_api_error(attr_key, message) }
  end
end

#format_key(key) ⇒ Object


387
388
389
# File 'lib/jsonapi/exceptions.rb', line 387

def format_key(key)
  @key_formatter.format(key)
end