Skip to content

Commit

Permalink
Reduce complexity of #serializable_errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hmnhf committed Jul 14, 2016
1 parent 370f033 commit 84e8c22
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/restful/jsonapi/serializable_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ module SerializableErrors
extend ActiveSupport::Concern

def serializable_errors(object)
errors = object.errors
prefix = object.class.to_s.demodulize.underscore

new_hash = errors.to_hash.map do |k, v|
v.map do |msg|
{ id: "#{prefix}.#{k}", title: msg }
errors = object.errors.to_hash.each_with_object([]) do |(k, v), array|
v.each do |msg|
array.push(id: "#{prefix}.#{k}", title: msg)
end
end.flatten
end

{ errors: new_hash }
{ errors: errors }
end
end
end
Expand Down

0 comments on commit 84e8c22

Please sign in to comment.