Skip to content

Commit

Permalink
Revert enumerable change
Browse files Browse the repository at this point in the history
  • Loading branch information
ericproulx committed Dec 20, 2024
1 parent ed08c8b commit 4478463
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions lib/grape/exceptions/validation_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class ValidationErrors < Base
ERRORS_FORMAT_KEY = 'grape.errors.format'
DEFAULT_ERRORS_FORMAT = '%<attributes>s %<message>s'

include Enumerable

attr_reader :errors

def initialize(errors: [], headers: {})
Expand All @@ -14,8 +16,6 @@ def initialize(errors: [], headers: {})
end

def each
return to_enum(:each) unless block_given?

errors.each_pair do |attribute, errors|
errors.each do |error|
yield attribute, error
Expand All @@ -37,16 +37,16 @@ def to_json(*_opts)
end

def full_messages
[].tap do |messages|
each do |attributes, error|
messages <<
I18n.t(ERRORS_FORMAT_KEY,
default: DEFAULT_ERRORS_FORMAT,
attributes: translate_attributes(attributes),
message: error.message)
end
messages.uniq!
messages = map do |attributes, error|
I18n.t(
ERRORS_FORMAT_KEY,
default: DEFAULT_ERRORS_FORMAT,
attributes: translate_attributes(attributes),
message: error.message
)
end
messages.uniq!
messages
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/grape/validations/attributes_iterator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Grape
module Validations
class AttributesIterator
include Enumerable

attr_reader :scope

def initialize(validator, scope, params)
Expand All @@ -13,8 +15,6 @@ def initialize(validator, scope, params)
end

def each(&block)
return to_enum(:each) unless block

do_each(@params, &block) # because we need recursion for nested arrays
end

Expand Down

0 comments on commit 4478463

Please sign in to comment.