Improve key formatting for nested hashes and disable by default #497
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since #486, key format is applied deeply to hashes and arrays that are
passed to
set!
,merge!
andarray!
:This also works for arrays and hashes extracted from objects:
This breaks code that relied on the previous behavior. Add a
deep_format_keys!
directive that can be used to opt into this newbehavior and disable it by default.
Moreover, as a side effect of #486, key format was also applied to the
result of nested blocks, making it impossible to change key format in
the scope of a block:
The string "vALUE" results from calling
"value".upcase.camelize(:lower)
. The same happens when trying tochange the key format inside of an
array!
block.This happens since key transformation was added in the
_merge_values
method, which is used both by
merge!
but also whenset!
is calledwith a block.
To restore the previous behavior, we pull the
_transform_keys
callup into
merge!
itself. To make sure extracted hashes and arrays keepbeing transformed (see comment/author example above), we apply
_transform_keys
in_extract_hash_values
and_extract_method_values
.This also aligns the behavior of
extract!
which was left out in #486:Finally, to fix
array!
, we make it call_merge_values
directlyinstead of relying on
merge!
.array!
then has to transform keysitself when a collection is passed to preserve the new behavior
introduced by #486.