8000 Added missing parameter name to InvalidParameterError when coercion validation fails by crevete · Pull Request #98 · nicolasblanco/rails_param · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added missing parameter name to InvalidParameterError when coercion validation fails #98

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

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/rails_param/param_evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def param!(name, type, options = {}, &block)
return unless params.include?(name) || check_param_presence?(options[:default]) || options[:required]

parameter_name = @context ? "#{@context}[#{name}]" : name
coerced_value = coerce(params[name], type, options)
coerced_value = coerce(parameter_name, params[name], type, options)

parameter = RailsParam::Parameter.new(
name: parameter_name,
Expand Down Expand Up @@ -73,14 +73,14 @@ def check_param_presence? param
!param.nil?
end

def coerce(param, type, options = {})
def coerce(param_name, param, type, options = {})
begin
return nil if param.nil?
return param if (param.is_a?(type) rescue false)

Coercion.new(param, type, options).coerce
rescue ArgumentError, TypeError
raise InvalidParameterError, "'#{param}' is not a valid #{type}"
raise InvalidParameterError.new("'#{param}' is not a valid #{type}", param: param_name)
end
end

Expand Down
Loading
0