mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactoring validate_missing_parameters to validate_required_parameters.
This commit is contained in:
parent
7a872e9d84
commit
3650edf039
1 changed files with 5 additions and 5 deletions
|
@ -81,7 +81,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_callstack_for_multiparameter_attributes(pairs)
|
def extract_callstack_for_multiparameter_attributes(pairs)
|
||||||
attributes = { }
|
attributes = {}
|
||||||
|
|
||||||
pairs.each do |(multiparameter_name, value)|
|
pairs.each do |(multiparameter_name, value)|
|
||||||
attribute_name = multiparameter_name.split("(").first
|
attribute_name = multiparameter_name.split("(").first
|
||||||
|
@ -146,7 +146,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# else column is a timestamp, so if Date bits were not provided, error
|
# else column is a timestamp, so if Date bits were not provided, error
|
||||||
validate_missing_parameters!([1,2,3])
|
validate_required_parameters!([1,2,3])
|
||||||
|
|
||||||
# If Date bits were provided but blank, then return nil
|
# If Date bits were provided but blank, then return nil
|
||||||
return if blank_date_parameter?
|
return if blank_date_parameter?
|
||||||
|
@ -172,14 +172,14 @@ module ActiveRecord
|
||||||
def read_other(klass)
|
def read_other(klass)
|
||||||
max_position = extract_max_param
|
max_position = extract_max_param
|
||||||
positions = (1..max_position)
|
positions = (1..max_position)
|
||||||
validate_missing_parameters!(positions)
|
validate_required_parameters!(positions)
|
||||||
|
|
||||||
set_values = values.values_at(*positions)
|
set_values = values.values_at(*positions)
|
||||||
klass.new(*set_values)
|
klass.new(*set_values)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks whether some blank date parameter exists. Note that this is different
|
# Checks whether some blank date parameter exists. Note that this is different
|
||||||
# than the validate_missing_parameters! method, since it just checks for blank
|
# than the validate_required_parameters! method, since it just checks for blank
|
||||||
# positions instead of missing ones, and does not raise in case one blank position
|
# positions instead of missing ones, and does not raise in case one blank position
|
||||||
# exists. The caller is responsible to handle the case of this returning true.
|
# exists. The caller is responsible to handle the case of this returning true.
|
||||||
def blank_date_parameter?
|
def blank_date_parameter?
|
||||||
|
@ -187,7 +187,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
# If some position is not provided, it errors out a missing parameter exception.
|
# If some position is not provided, it errors out a missing parameter exception.
|
||||||
def validate_missing_parameters!(positions)
|
def validate_required_parameters!(positions)
|
||||||
if missing_parameter = positions.detect { |position| !values.key?(position) }
|
if missing_parameter = positions.detect { |position| !values.key?(position) }
|
||||||
raise ArgumentError.new("Missing Parameter - #{name}(#{missing_parameter})")
|
raise ArgumentError.new("Missing Parameter - #{name}(#{missing_parameter})")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue