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.



299
300
301
302
303
# File 'lib/jsonapi/exceptions.rb', line 299

def initialize(resource)
  @error_messages = resource._model.errors.messages
  @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.



297
298
299
# File 'lib/jsonapi/exceptions.rb', line 297

def error_messages
  @error_messages
end

#resource_relationshipsObject (readonly)

Returns the value of attribute resource_relationships.



297
298
299
# File 'lib/jsonapi/exceptions.rb', line 297

def resource_relationships
  @resource_relationships
end

Instance Method Details

#errorsObject



309
310
311
312
313
# File 'lib/jsonapi/exceptions.rb', line 309

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



305
306
307
# File 'lib/jsonapi/exceptions.rb', line 305

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