-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Feature: Allows procs with arity 1 to validate and use custom messages #2333
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
Changes from 8 commits
63d89b2
69be761
035bc4a
b1a38c0
49d5a5a
7c8f4ad
c5b1125
985763c
3a15d5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ def validate_param!(attr_name, params) | |
unless check_values(param_array, attr_name) | ||
|
||
raise validation_exception(attr_name, message(:values)) \ | ||
if @proc && !param_array.all? { |param| @proc.call(param) } | ||
if @proc && !validate_proc(@proc, param_array) | ||
end | ||
|
||
private | ||
|
@@ -68,6 +68,17 @@ def check_excepts(param_array) | |
param_array.none? { |param| excepts.include?(param) } | ||
end | ||
|
||
def validate_proc(proc, param_array) | ||
case proc.arity | ||
when 0 | ||
param_array.all? { |_param| proc.call } | ||
when 1 | ||
param_array.all? { |param| proc.call(param) } | ||
else | ||
raise ArgumentError, 'proc arity must be 0 or 1' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we get some kind of useful call stack with a line number such as that the developer knows where the error comes from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, considering the ruby and rails versions that grape supports, the stack trace will show every sequence leading to this raise statement. |
||
end | ||
end | ||
|
||
def except_message | ||
options = instance_variable_get(:@option) | ||
options_key?(:except_message) ? options[:except_message] : message(:except_values) | ||
|
Uh oh!
There was an error while loading. Please reload this page.