Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support per-key custom errors for array paths #665

Merged
merged 1 commit into from
Aug 21, 2020

Conversation

tadeusz-niemiec
Copy link

@tadeusz-niemiec tadeusz-niemiec commented Aug 19, 2020

Resolves #663

This allows using custom errors by a key without an index when used in .each.
I guess there should be a better way to check if this is related to .each than by checking the keys array size, let me know if you have any ideas.

@tadeusz-niemiec tadeusz-niemiec force-pushed the master branch 6 times, most recently from 993b98e to e81c6ad Compare August 19, 2020 13:23
Comment on lines 73 to 74
non_index_keys = []
keys.each { |k| non_index_keys << k unless k.is_a?(Numeric) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two lines are non_index_keys = keys.reject { |k| k.is_a?(Integer) }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, I tried to use filter but it was unavailable in the 2.4 version and I totally forgot about reject, thanks :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruby's version of filter is select which IMO makes more sense because it's not obvious if filter filters in or out

@dry-bot
Copy link
Contributor

dry-bot commented Aug 20, 2020

Codacy Here is an overview of what got changed by this pull request:

Complexity increasing per file
==============================
- lib/dry/validation/messages/resolver.rb  2
         

See the complete overview on Codacy

@solnic solnic merged commit f9df1b9 into dry-rb:master Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support per-key custom errors for array paths
4 participants