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

Make validators accept lambdas without record argument #45118

Merged
merged 1 commit into from
May 18, 2022

Conversation

fatkodima
Copy link
Member

Fixes #45117.

Copy link
Member

@jonathanhefner jonathanhefner left a comment

Choose a reason for hiding this comment

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

It looks like this pattern also occurs elsewhere:

I feel like we should be consistent in what we support, so what do you think about factoring out a resolve_value(record, value) method? It could live in a ResolveValue module in active_model/validations/resolve_value.rb, which could be included where required.

(Alternatively, we could add it as a utility method to the Validator or EachValidator class, but that feels a little off.)

Note that in some cases we check value.respond_to?(:call) instead of Proc === value, so we would (unfortunately) probably have to check for both to avoid breaking existing code.

@fatkodima
Copy link
Member Author

Ooh, I was sure that this is already supported in other places. Thanks for the suggestion, I will do that.

@fatkodima fatkodima force-pushed the comparison-validator-lambda branch from 0359071 to a8f8c47 Compare May 17, 2022 21:50
@fatkodima
Copy link
Member Author

Updated.

@fatkodima fatkodima changed the title Make comparison validator working with lambdas Make validators accept lambdas without record argument May 17, 2022
@fatkodima fatkodima force-pushed the comparison-validator-lambda branch from a8f8c47 to 00b269e Compare May 18, 2022 16:54
@jonathanhefner jonathanhefner merged commit 08555b9 into rails:main May 18, 2022
@jonathanhefner
Copy link
Member

Thank you, @fatkodima! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ComparisonValidator example code does not work
2 participants