Skip to content

Commit

Permalink
drop conditionals in conversion logic
Browse files Browse the repository at this point in the history
there is no reason to `convert_hashes_to_parameters` with an assignemt
flag.  The caller knows whether or not it wants the value assigned.  We
should just change the uncommon case (not writing to the underlying
hash) to just call the conversion method and return that value.
  • Loading branch information
tenderlove committed Jul 21, 2015
1 parent c75153d commit 5046d51
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions actionpack/lib/action_controller/metal/strong_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,14 @@ def []=(key, value)
# params.fetch(:none, 'Francesco') # => "Francesco"
# params.fetch(:none) { 'Francesco' } # => "Francesco"
def fetch(key, *args, &block)
convert_hashes_to_parameters(
key,
convert_value_to_parameters(
@parameters.fetch(key) {
if block_given?
yield
else
args.fetch(0) { raise ActionController::ParameterMissing.new(key) }
end
},
false
}
)
end

Expand Down Expand Up @@ -475,7 +473,7 @@ def transform_keys!(&block)
# optional code block is given and the key is not found, pass in the key
# and return the result of block.
def delete(key, &block)
convert_hashes_to_parameters(key, @parameters.delete(key), false)
convert_value_to_parameters(@parameters.delete(key))
end

# Returns a new instance of <tt>ActionController::Parameters</tt> with only
Expand Down Expand Up @@ -555,9 +553,9 @@ def new_instance_with_inherited_permitted_status(hash)
end
end

def convert_hashes_to_parameters(key, value, assign_if_converted=true)
def convert_hashes_to_parameters(key, value)
converted = convert_value_to_parameters(value)
@parameters[key] = converted if assign_if_converted && !converted.equal?(value)
@parameters[key] = converted unless converted.equal?(value)
converted
end

Expand Down

0 comments on commit 5046d51

Please sign in to comment.